spliting string by one of several characters? NEWBIE

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!
 
K

Kevin Spencer

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.
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top