VB.NET String.Split 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7919253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET String.Split method?
提问by Chris
I'm having some issues using the String.Split method, Example here:
我在使用 String.Split 方法时遇到了一些问题,示例如下:
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.
以上,在 PHP(我的母语!)中会在消息框中返回一些 here 和 URLhere。
In VB.NET I get:
在 VB.NET 中,我得到:
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!
String.Split 仅适用于标准字符吗?我似乎无法弄清楚这一点。我相信这是非常简单的事情!
回答by ja72
This is what you need to do, to prevent the string from being converted to a Chararray.
这是您需要做的,以防止将字符串转换为Char数组。
Dim text As String = "something here -:- urlhere"
Dim parts As String() = text.Split(New String() {" -:- "}, StringSplitOptions.None)
This is the System.Stringmember function you need to use in this case
这是System.String您在这种情况下需要使用的成员函数
Public Function Split(ByVal separator As String(), ByVal options As StringSplitOptions) As String()

