55 pts.
 How to Split a String using Visual Basic
I want to Split the String sMemberName=Totalmarket <null> <null> C10A and store it separately how can i do it using Visual Basic

Software/Hardware used:
ASKED: March 14, 2008  8:54 AM
UPDATED: March 15, 2008  3:45 AM

Answer Wiki:
I'm not sure I quite understand the question, but you can use the Left(), Right() or Mid() functions to get a subset of a given string taken from the left, right or middle of a string. <pre>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"</pre> You can use InStr() or InStrRev() to get the first or last occurrence of one string in another. So your end code may be something like: <pre> 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"</pre>
Last Wiki Answer Submitted:  March 14, 2008  5:37 pm  by  YuvalShavit   905 pts.
All Answer Wiki Contributors:  YuvalShavit   905 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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.

 750 pts.