Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi Everyone,

 

I have a string in the form of

 

Blah1, Blah2, Blah3, Blah4, Blah5

 

I need to strip the Blah's and store them as separate string variables such as

 

strVar1 = Blah1

strVar2 = Blah2

strVar3 = Blah3

etc

etc

 

The string will be of different lengths and could contain 3 Blah's or 8 Blahs so the string length is never constant.

 

I get the feeling that a regular expression is the solution but haven't got a clue how to write one of these to do the job. If anyone could help it would be very much appreciated. Thanks in advance.

 

Martin

  • Administrators
Posted

You could use the simple string.Split method

dim s as string = "Blah1, Blah2, Blah3, Blah4, Blah5" 'or whatever the string is
dim ans() as string = s.split(",")

 

or if you really require regular expressions then something like

Dim r as new RegEx("(,)")
Dim s as String = "Blah1, Blah2, Blah3, Blah4, Blah5"
dim ans() as String = r.Split(s)

should do it. may not be exact as I don't have VS on this PC.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...