Simple question, but I can't find the solution

vcvc

Freshman
Joined
Nov 14, 2003
Messages
27
I'm sure you'll all be rolling your eyes and throwing things at me, but here goes with what should be a simple question that I have not been able to find a solution to:
I have a string

FOO,BAR/THIS(THAT)
I need to find the delimiting characters (/,()) and split the string...no problem so far.

The problem is I need to find the delimiting chars and include them with the splits.
eg: the string FOO,BAR/THIS(THAT)
should produce
FOO,
BAR/
THIS(
THAT)

I know this should be simple and I'm sure I'll suddenly awake at 3:00am slapping my forehead with a Homer "D'Oh"
 
Didn't you try with IndexOf ?
And... what it is doing in RegularExpression ?
Aren't regular expression for validating chars in a string to determine which one are valid or not ?
 
RegEx isn't my strong point (only just started to learn it...) but
Visual Basic:
' the following is close (\w*[,|/|\\|\(|\)]+)
Dim s() As String = Regex.Split("FOO,BAR/THIS(THAT)", "(\w*[,|/|\\|\(|\)]+)", RegexOptions.IgnorePatternWhitespace Or RegexOptions.Singleline)
happily delimits and includes the delimiters - unfortunately it also includes several empty strings - not 100% on what I'm matching there :confused: so hopefully somebody can fix / explain what the hell it is doing. :rolleyes:

Edit: similar (has the same problem for now) but if the items are always ASCII and the delimiters may vary try
Code:
([a-zA-Z]*[^a-zA-Z])
 
Last edited:
Hey thanks PlausiblyDamp!

That worked great!

I tinkered with the expression, I always ended up with a bunch of empty strings too, but it didn't really matter as I am looping through the resulting array to match to values from a separate XML.

Arch4Angel - thats why I'm using regular expressions. Strings can be painfully slow. Not to mention the overhead of countless lines of string manipulation to perform what a regex can do in one clean line.
 
Back
Top