Hi,
How should I split a string separated by a multi-character delimiter in VB?
i.e. If my string is say - Elephant##Monkey, How do I split it with "##" ?
Thanks!
Hi,
How should I split a string separated by a multi-character delimiter in VB?
i.e. If my string is say - Elephant##Monkey, How do I split it with "##" ?
Thanks!
Use Regex.Split.
string whole = "Elephant##Monkey";
string[] split = Regex.Split(whole, "##");
foreach (string part in split)
Console.WriteLine(part);
Be careful however, because this isn't just a string, it's a complete Regular Expression. Some characters might need escaping, etc. I suggest you look them up.
Dim words As String() = myStr.Split(new String() { "##" },
StringSplitOptions.None)
Dim s As String = "Elephant##Monkey"
Dim parts As String() = s.Split(New Char() {"##"c})
Dim part As String
For Each part In parts
Console.WriteLine(part)
Next