2013-04-10 39 views
0

我有一個字符串變量包含「開山鼻祖salathia」 ......
我想存儲salathia存儲到另一個字符串....怎麼用vb.net需要字符串的第二個單詞。怎麼做?

這樣做在asp.net
+0

什麼構成一個字奔跑 - 是什麼,做不包含空格的單詞? – 2013-04-10 11:38:03

+0

你試過我的答案了嗎?我有一個疑問。該變量是否只包含字符串「Welcom salathia」或者是否包含其他字符? – 2013-04-10 11:49:49

回答

0

方法1:

Dim s As String = "Welcom salathia" 
s = s.Split(" ".ToCharArray)(1) 

方式2:

Dim s As String = "Welcom salathia" 
s = s.substring(s.index(" ")) 
1

您可以使用拆分並獲取第二個字符串。

Dim s As String = "Welcom salathia" 
' Split string based on spaces 
Dim words As String() = s.Split(New Char() {" "c}) 
+0

我不知道分裂... plz提供示例代碼 – Partap 2013-04-10 11:38:52

+0

Dim txt_addedbyuser As String = Welcome_id.Text Dim string_split As String = txt_addedbyuser.Split(New Char(){「」c})顯示錯誤'value類型的一維字符串數組不能轉換爲字符串' – Partap 2013-04-10 11:43:32

+0

在vb.net中,你也可以寫:Dim words As String()= Split(s,「」) – Amegon 2013-04-10 12:12:19

3

可以使用包含函數獲取第一空間和它的索引,然後直到下一個空格發現得到的字符。

拆分功能在這方面也很有用。這也將是更簡單的方法。

0

的情況下有空格

Dim s As String = "Welcom salathia" 
    ' Split string based on spaces, gurad against runs of space 
    Dim words() As String = s.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries) 
    Debug.WriteLine(words(1)) 'show second word 
相關問題