Parse and split string

G

Guest

Hi,
I have problem with string parsing. I have string for ex.:

"abc def" abc def

and I need string array:

abc def
abc
def

I tried to use Regex class and Split function, but I don't know how do it (
I don't know pattern format for split)
 
S

Scott M.

I'm not sure why below, when you tell us what your string is, you have some
of it in quotes and some not.

What exactly is the starting string: "abc def" or "abc def abc def"?

Here are some thoughts

[VB.NET]
dim theString As String = "abc def"
dim theResultString As String = theString.split(" ")
Dim theFinalStuff As Array(2)
theFinalStuff(0) = theString
theFinalStuff(1) = theResultString(0)
theFinalStuff(2) = theResultString(1)
 
J

Jon Skeet [C# MVP]

Scott M. said:
I'm not sure why below, when you tell us what your string is, you have some
of it in quotes and some not.

What exactly is the starting string: "abc def" or "abc def abc def"?

The way I understand it, the initial string is

"abc def" abc def

which should be split into

abc def
abc
def

None of the above are string literals with extra quotes - that's the
actual data.

Just my understanding of it...
 
W

William Stacey [MVP]

Here is a general purpose SplitQuoted method that will split on multiple
delimiters and ignore any of the delimiters inside double quotes. So things
like:
"one , two", three four

will split to three fields as you may want (assuming space and comma " ," is
the delim string)
..
http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPvDxLKC6rAAhLsQ!352.entry

Things like:
one,,,two
one two

Will split to two fields ignoring multiple delimiters in a row. So if you
want the empty fields, put empty string in quotes such as:
one,"","","",two.

HTH
 

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

Similar Threads


Top