Simple question, but I can't find the solution

vcvc

Active member
Joined
Nov 14, 2003
Messages
27
Im sure youll 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 Im sure Ill suddenly awake at 3:00am slapping my forehead with a Homer "DOh"
 
Didnt you try with IndexOf ?
And... what it is doing in RegularExpression ?
Arent regular expression for validating chars in a string to determine which one are valid or not ?
 
RegEx isnt my strong point (only just started to learn it...) but
Code:
 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 Im 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 by a moderator:
Hey thanks PlausiblyDamp!

That worked great!

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

Arch4Angel - thats why Im 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