Parse and split string

  • Thread starter Thread starter Guest
  • Start date Start date
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)
 
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)
 
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...
 
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
 
Back
Top