我有一个字符串。例如stringone/string2
如何获取“/”之前和“/”之后的部分
Dim Word As String = "stringone/string2"
Dim wordArr As String() = Word.Split("/")
Dim stringBefore As String = wordArr(???)
Dim stringBefore As String = wordArr(???)
你下一步怎么做
Split() 返回一个数组。第一个元素位于索引 0(零),第二个元素位于索引 1(一),依此类推...
您应该检查以确保返回的数组是您预期的大小(至少),否则您将在尝试访问不存在的索引槽时出错。
Dim Word As String = "stringone/string2"
Dim wordArr As String() = Word.Split("/")
If wordArr.Length = 2 Then
Dim stringBefore As String = wordArr(0)
Dim stringAfter As String = wordArr(1)
Debug.Print("stringBefore = " & stringBefore)
Debug.Print("stringAfter = " & stringAfter)
End If
*顺便说一句,您发布的代码不是VB6,而是VB.Net。