我在使用 String.Split 方法时遇到了一些问题,例子如下:
Dim tstString As String = "something here -:- URLhere"
Dim newtstString = tstString.Split(" -:- ")
MessageBox.Show(newtstString(0))
MessageBox.Show(newtstString(1))
在PHP中(我的母语!),上面的代码将在消息框中返回something here和URLhere。
在VB.NET中,我得到:
something here
并且
: (colon)
字符串分割只能使用标准字符吗?我似乎无法弄清楚这个问题。不过我相信这只是一个非常简单的问题!
newTstString
是{"something", "here", "-:-", "URLhere"}
,这是我现在所期望的,因为我知道tstString.Split(" -:- ")
在功能上等同于tstString.Split(" ")
。此问题中列出的输出是您运行tstString.Split("-")
时得到的结果,尽管在结果数组中会有第三个元素" URLhere"
。 - Lance U. Matthews