IOutils.Scanner 1.0.1

dotnet add package IOutils.Scanner --version 1.0.1
NuGet\Install-Package IOutils.Scanner -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IOutils.Scanner" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IOutils.Scanner --version 1.0.1
#r "nuget: IOutils.Scanner, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IOutils.Scanner as a Cake Addin
#addin nuget:?package=IOutils.Scanner&version=1.0.1

// Install IOutils.Scanner as a Cake Tool
#tool nuget:?package=IOutils.Scanner&version=1.0.1

Java-like Scanner for C#

Scanner is an input reader for C#, which reads numbers and text in the Java's Scanner style.
Original idea belongs to Svetlin Nakov - https://github.com/nakov/Nakov.io.cin
I only added reading from file and renamed to Scanner.

Install the NuGet Package

You can install the NuGet package IOutils.Scanner:

Install-Package IOutils.Scanner

Sample C++ Code

public class Main {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);
       System.out.println("Enter a number:");

       int number = sc.nextInt();

       System.out.println("Thanks! You entered a number " + number);

   }
}

Corresponsing C# Code

using System;
using IOutils;

public class EnteringNumbers
{
    static void Main()
    {
        Scanner sc = new Scanner();
        Console.WriteLine("Enter a number:");
        
        int? number = sc.nextInt();
        
        Console.WriteLine("Thanks! You entered a number " + number.Value);
    }
}

More Detailed Example

using System;
using System.Collections.Generic;
using System.IO;
using IOutils;

public class ScannerExample
{
    static void Main()
    {
        // Console test

        Scanner consoleScanner = new Scanner();

        Console.WriteLine("Console test\n");

        Console.Write("Enter your name: ");
        string name = consoleScanner.NextToken();
        Console.WriteLine("Your name is " + name);

        Console.Write("Enter a positive integer number N: ");
        int? n = consoleScanner.NextInt();
        Console.Write("Enter N decimal numbers separated by a space: ");
        decimal[] numbers = new decimal[n.Value];
        for (int i = 0; i < n; i++)
        {
            numbers[i] = consoleScanner.NextDecimal().Value;
        }
        Array.Sort(numbers);
        Console.WriteLine("The numbers in ascending order: {0}",
            string.Join(' ', numbers));


        // File test

        Scanner fileScanner = new Scanner(File.OpenRead(
            @"..\..\..\Test\test.txt"));

        Console.WriteLine("\nFile test\n");

        LinkedList<double> nums = new LinkedList<double>();
        double? x = fileScanner.NextDouble();
        while (x != null)
        {
            nums.AddLast(x.Value);
            x = fileScanner.NextDouble();
        }

        Console.WriteLine("Numbers in file:");
        foreach (double num in nums)
        {
            Console.Write(num + " ");
        }
    }
}

test.txt contents:

  7  
 12  5.6  32.1      54.44   531,2    909.0001     0.0001   
     
  234,345  0,222 3.54 5
  
 5    6.4
  
   

This is a sample input and output from the above example:

Console test

Enter your name: Victor
Your name is Victor
Enter a positive integer number N: 5
Enter N decimal numbers separated by a space: 10.4  12.001 123   4  32,02
The numbers in ascending order: 4 10,4 12,001 32,02 123

File test

Numbers in file:
7 12 5,6 32,1 54,44 531,2 909,0001 0,0001 234,345 0,222 3,54 5 5 6,4
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 288 12/15/2022
1.0.0 254 12/14/2022

Methods are nullable now