2011-10-27 54 views
8

我在使用該方法String.Split一些問題,這裏舉例:VB.NET String.Split方法?

Dim tstString As String = "something here -:- URLhere" 
Dim newtstString = tstString.Split(" -:- ") 
MessageBox.Show(newtstString(0)) 
MessageBox.Show(newtstString(1)) 

以上,在PHP(!我的母語)將在這裏和URLhere在消息框返回的東西。

在VB.NET我得到:

something here 

: (colon) 

是否String.Split只與標準字符工作?我似乎無法弄清楚這一點。我相信這是非常簡單的事情!

+0

我有它通過改變線路工作: 昏暗newtstString =斯普利特(tstString,「 - : - 」 ) 雖然我仍然不確定爲什麼String.Split不能正常工作。 – Chris

+0

我無法複製。 – Oded

+1

請參閱http://msdn.microsoft.com/en-us/library/system.string.split.aspx string.split() – Jim

回答

16

這是您需要做的,以防止將字符串轉換爲Char陣列。

Dim text As String = "something here -:- urlhere" 
    Dim parts As String() = text.Split(New String() {" -:- "}, StringSplitOptions.None) 

這是你需要在這種情況下使用System.String成員函數

Public Function Split(ByVal separator As String(), ByVal options As StringSplitOptions) As String()