【发布时间】:2011-10-27 16:34:37
【问题描述】:
我在使用 String.Split 方法时遇到了一些问题,示例如下:
Dim tstString As String = "something here -:- URLhere"
Dim newtstString = tstString.Split(" -:- ")
MessageBox.Show(newtstString(0))
MessageBox.Show(newtstString(1))
上面的内容,在 PHP(我的母语!)中会在消息框中返回一些 here 和 URLhere 的内容。
在 VB.NET 中我得到:
something here
与
: (colon)
String.Split 是否仅适用于标准字符?我似乎无法弄清楚这一点。不过,我敢肯定这是非常简单的事情!
【问题讨论】:
-
我已经通过将行更改为: Dim newtstString = Split(tstString, "-:-") 虽然我仍然不确定为什么 String.Split 不能正常工作。
-
查看 msdn.microsoft.com/en-us/library/system.string.split.aspx 了解 string.split() 的所有重载
-
我在调查String.Split is not removing the split text, only the first letter 之后来到这里,当我运行您的代码时
newTstString是{ "something", "here", "-:-", "URLhere" },这是我现在所期望的,因为我知道tstString.Split(" -:- ")在功能上是等效的到tstString.Split(" ")。这个问题中列出的输出是运行tstString.Split("-")会得到的结果,尽管结果数组中会有第三个元素" URLhere"。