spliting string by one of several characters? NEWBIE

  • Thread starter Thread starter jason
  • Start date Start date
J

jason

Hello.

Given string "yyy/zzz/lll.bbb \ggg\rrr\zzz"

Id like to split (in vb) by characters: /.\ and space

yeilding:

yyy
zzz
lll
bbb
ggg
rrr
zzz


flirting with the following code that's not working:

<vbcode>

dim tosplit as string
tosplit = available.selecteditem.text
dim threethings() as string
threethings=tosplit.split("[\.]")
p1=threethings(0)
p2=threethings(2)
response.write(p1+" "+p2)

</vbcode>

Requires Regex? Got sample code?

Many thanks in advance for any info or help with this!
 
Quick and dirty:

Dim aryValues() As String = someString.Replace("/", "\").Replace(".",
"\").Split(New [Char]() {'\'})

What this does is to replace the other 2 characters with the third, and
split the resulting string by the third.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
My apologies. Upon further reflection, I realized that you don't need to do
the Replace part at all:

Dim aryStrings() As String = someString.Split(New [Char]() {'\', '/', '.'})

The String.Split method takes an array of Char as an argument. So, you can
put as many delimiter characters in there as you like.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Back
Top