我希望打破我的字符串中的单词

时间:2014-08-07 07:00:21

标签: vb.net

我的字符串是myname mynickname

我希望在我的字符串mynamemynickname中获得2个字。

如何做" vb.net"

2 个答案:

答案 0 :(得分:0)

dim xstr as string="myname mynickname"

dim xMyname as string=xstr.Split(" ", 
options:=StringSplitOptions.RemoveEmptyEntries)(0)
dim Name as string=xstr.Split(" ", 
options:=StringSplitOptions.RemoveEmptyEntries)(1)

答案 1 :(得分:0)

您应该使用String.Split方法:

Sub Sample()
    Dim theStringIWantToSplit As String = "myname mynickname"

    '' if there is a possiblility of multiple spaces between the words and you want to ignore them
    Dim sa() As String = theStringIWantToSplit.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)

    '' otherwise it is much simpler
    Dim sa1() As String = theStringIWantToSplit.Split(" "c)
End Sub