C#: split a string into runs of characters, numbers and delimited strings and process it
Posted
by
nrkn
on Stack Overflow
See other posts from Stack Overflow
or by nrkn
Published on 2011-01-14T04:39:10Z
Indexed on
2011/01/14
4:53 UTC
Read the original article
Hit count: 200
OK my regex is a bit rusty and I've been struggling with this particular problem...
I need to split and process a string containing any number of the following, in any order:
- Chars (lowercase letters only)
- Quote delimited strings
- Ints
The strings are pretty weird (I don't have control over them). When there's more than one number in a row in the string they're seperated by a comma. They need to be processed in the same order that they appeared in the original string.
For example, a string might look like:
abc20a"Hi""OK"100,20b
With this particular string the resulting call stack would look a bit like:
ProcessLetters( new[] { 'a', 'b', 'c' } );
ProcessInts( 20 );
ProcessLetters( 'a' );
ProcessStrings( new[] { "Hi", "OK" } );
ProcessInts( new[] { 100, 20 } );
ProcessLetters( 'b' );
What I could do is treat it a bit like CSV, where you build tokens by processing the characters one at a time, but I think it could be more easily done with a regex?
© Stack Overflow or respective owner