469,357 Members | 1,832 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

string.split only accept char[] separator

Hi,

I have a string that needs to be parsed into the string[]. The separator is
not char[]. It is something like " at ". With current string.Split function,
it doesn't work. Is there any exist functions like "Split" that I can use to
do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry
Jul 21 '05 #1
4 2296
String.Split is designed to be pretty basic. You need to use something like
a regex here. For example, given the string

"one::two::three::four::five::six"

this expression:

\w+[^::]

will give you six matches, each with one number.

There's probably a better way (Regex object have a Split method as well),
but you get the idea.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Henry Chen" <he********@postiive-it.com.au> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry

Jul 21 '05 #2
"Henry Chen" <he********@postiive-it.com.au> wrote in
news:eI**************@TK2MSFTNGP11.phx.gbl:
Hi,

I have a string that needs to be parsed into the string[]. The
separator is not char[]. It is something like " at ". With
current string.Split function, it doesn't work. Is there any
exist functions like "Split" that I can use to do the job? Any
idea of the simpliest way to do the job?


Henry,

Use the Regex.Split function (found in the
System.Text.RegularExpressions namespace).

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 21 '05 #3
See string.ToCharArray(). For performance and simplicity, I'd recommend
string.Split(...) over RegEx.

Scott
I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Jul 21 '05 #4
Henry,
There are three Split functions in .NET:

Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.

If you are using C#, you can reference the Microsoft.VisualBasic.dll
assembly to use the first function.

Hope this helps
Jay

"Henry Chen" <he********@postiive-it.com.au> wrote in message
news:eI**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a string that needs to be parsed into the string[]. The separator is not char[]. It is something like " at ". With current string.Split function, it doesn't work. Is there any exist functions like "Split" that I can use to do the job? Any idea of the simpliest way to do the job?

Thanks in advance,
Henry

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Carlos Ribeiro | last post: by
10 posts views Thread by Alex | last post: by
3 posts views Thread by tvn007 | last post: by
7 posts views Thread by Mad Scientist Jr | last post: by
2 posts views Thread by James | last post: by
4 posts views Thread by Henry Chen | last post: by
12 posts views Thread by John | last post: by
10 posts views Thread by vunet.us | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.