CMedina CMedina -4 years ago 75
Vb.net Question

split string return diferent result

I have a problem to split text

Dim strText as String = "Listings/Listing"
Dim separator as String = "Listings/"
Dim arr as string() = strText.split(separator)


My code return 3 results

arr(0) = ""
arr(1) = "istings/"
arr(2) = "isting"


What is the problem? Why is this happening? I need to get a
Listing
from
strText


Test: http://rextester.com/VNQ39065

Answer Source

Try it this way instead,

 Dim StrText As String = "Listings/Listing"
 Dim arr as string() = Split(StrText, "Listings/")

The .split method works differently, and is character based using that particular overload, so it only uses the first "L"c in your separator string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download