split question

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

I am trying to split a comma-delimited string into a string array.
unfortunately, if the string doesn't contain a comma, the resulting array is
Nothing. other than using vb6 compatibility, is there another option?

thanks,

Craig Buchanan
 
maybe check for the indexof the comma on the string first if there is no
index returned then dont split it to get teh string back, but if there is an
index returned then use the split method
 
Are you certain? In these types of cases it really helps if you post a few
lines of code that demonstrates what you are doing.

Tom
 
* "Craig Buchanan said:
I am trying to split a comma-delimited string into a string array.
unfortunately, if the string doesn't contain a comma, the resulting array is
Nothing. other than using vb6 compatibility, is there another option?

Post your code.

Do you use 'Strings.Split' or the string's 'Split' method for splitting?
 
Craig,
You should have a single element array returned, with the string in the
first element!

Dim s As String = "this is a test"
Dim values() As String = s.Split(","c)

Debug.WriteLine(values(0))

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

Can you post code?

Hope this helps
Jay
 
Back
Top