I have an input string that looks something like this:
4 Bob 32 Joe 64 Sue 123 Bill 42
Where the 4 indicates the number of string integer pairs to follow. My current way of processing this looks something like this:
var strings = input.Split(' ');
int count = Int32.Parse(strings[0]);
for ( int i = 0; i < count; i++ )
{
string name = strings[count*2 + 1];
int number = Int32.Parse(strings[count*2 + 1]);
ProcessPerson(name, number);
}
This feels quite cumbersome. Is there some library in C# that can wrap a string and give me services like "readInt" and "readString". I would ultimately like to have something like:
int count = input.ReadInt();
for(int i = 0; i<count; i++)
{
ProcessPerson(input.ReadString(), input.ReadInt());
}
It doesn't look like that much of an improvement in this case, but my actual object model is a bit more complicated. I know other languages have facilities to o things like this, but I can't recall any .net libraries to simply read from the front of a string.
((\d+) ([a-zA-Z]+))+could do the work for you... Just let me know if you want an example. Maybe you're looking for another solution :)