需要字符串的第二个字。怎么做?

时间:2013-04-10 11:35:47

标签: asp.net vb.net

我有一个字符串变量,其中包含“Welcom salathia”...
我想将商店salathia存储到另一个字符串....如何使用vb.net在asp.net中执行此操作

4 个答案:

答案 0 :(得分:3)

您可以使用contains函数获取第一个空格及其索引,然后获取字符,直到找到下一个空格。

分割功能在此主题中也很有用。而且它也会更容易。

答案 1 :(得分:1)

您可以使用split并获取第二个字符串。

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

答案 2 :(得分: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(" ")) 

答案 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