Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm having some issues using the String.Split method, Example here:

Dim tstString As String = "something here -:- URLhere"
Dim newtstString = tstString.Split(" -:- ")
MessageBox.Show(newtstString(0))
MessageBox.Show(newtstString(1))

The above, in PHP (my native language!) would return something here AND URLhere in the message boxes.

In VB.NET I get:

something here

AND

: (colon)

Does the String.Split only work with standard characters? I can't seem to figure this one out. I'm sure it's something very simple though!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
917 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is what you need to do, to prevent the string from being converted to a Char array.

    Dim text As String = "something here -:-  urlhere"
    Dim parts As String() = text.Split(New String() {" -:- "}, StringSplitOptions.None)

This is the System.String member function you need to use in this case

Public Function Split(ByVal separator As String(), ByVal options As StringSplitOptions) As String()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...