split() question

  • Thread starter Thread starter KC
  • Start date Start date
K

KC

Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't know
how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken
 
KC said:
Can I do a split() on a string where the delimiter is one or more space
characters? I have a string with spaces between the numbers but I don't know
how many. You can do this easy in Perl, but VB.net ain't Perl...

Ken

You have to do like this, atleast I don't know any other way

dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while
 
Use Regular Expressions.

Richard said:
You have to do like this, atleast I don't know any other way

dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while
 
dim str as string = "234 23 42 234 234 234"
str = str.split(" ")
dim moreSpaces as integer = str.indexof(" ")
while morespaces <> -1
str = str.split(" ")
moreSpaces = str.indexof(" ")
end while

LOL
My bad I thought i was another operation,
It will work with split, but there might be some empty strings in the array
you are getting
 
Ken,
As Juan suggested, you can use RegEx.Split...

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.

Hope this helps
Jay
 
Back
Top