How to Split a String using Visual Basic
sMemberName=Totalmarket <null> <null> C10A and store it separately
how can i do it using Visual Basic
Dim subString as String
subString = Left("One two three", 3) ' subString = "One"
subString = Right("One two three", 5) 'subString = "three"
subString = Mid("One two three", 5, 3) 'subString = "two"
subString = Mid("One two three", 5) 'subString = "two three"
Dim bigString as String
Dim leftString as String
Dim rightString as String
Dim splitAt as Integer
bigString = "hello world"
splitAt = InStr(bigString, "world") ' splitAt = 7
leftString = Left(bigString, splitAt-1) ' leftString = "hello "
' (note the space after "hello")
rightString = Mid(bigString, splitAt) ' rightString = "world"
Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.
BobBeechey | Mar 15 2008 3:45AM GMT
In flavours of visualo basic .NET you can use the Split function. It normally splits a string into substrings based on the space character as separator but, assuming your <null> implies the need to use chr(0) as separator, this is easily done.
The following code gives the hint:
Dim TheString As String = "First" + vbNullChar.ToString() + "Thing"
Dim TheArray As String() = Split(TheString, vbNullChar)
TheArray.Length will now, correctly, be 2 and TheArray(0) will be “First” and TheArray(1) will be “Thing”.
The use of two <null> consecutively as in your answer will lead to production of an intervening empty string(string of length zero) in the output array.