我的字符串是myname mynickname
。
我希望在我的字符串myname
和mynickname
中获得2个字。
如何做" vb.net"
答案 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