Is there an equivalent to the Scanner class in C# for strings?

In Java I can pass a Scanner a string and then I can do handy things like, scanner.hasNext() or scanner.nextInt(), scanner.nextDouble() etc.

This allows some pretty clean code for parsing a string that contains rows of numbers.

How is this done in C# land?

If you had a string that say had:

"0 0 1 22 39 0 0 1 2 33 33"

In Java I would pass that to a scanner and do a

while(scanner.hasNext()) 
    myArray[i++] = scanner.nextInt();

Or something very similar. What is the C#’ ish way to do this?

Leave a Comment