我有一个文本框(DropDownList1),其中包含以下格式的 46 个字符的字符串:
(字符串 1,字符串 2,字符串 3)
我想以这种方式获取不带逗号的字符串值:
一个=字符串1 b=字符串2 c=字符串3
所以我使用了下面的代码:
Dim a As String
Dim b As String
Dim c As String
Dim x As Integer = InStr(1, DropDownList1.Text, ",", CompareMethod.Text) + 1
Dim y As Integer = InStr(InStr(1, DropDownList1.Text, ",", CompareMethod.Text) + 1, DropDownList1.Text, ",") - 1
Dim z As Integer = Len(DropDownList1.Text)
a = Mid(DropDownList1.Text, 1, InStr(1, DropDownList1.Text, ",", CompareMethod.Text) - 1)
b = Mid(DropDownList1.Text, x, y) _
'InStr(1, DropDownList1.Text, ",", CompareMethod.Text) + 1, _
'InStr(InStr(1, DropDownList1.Text, ",", CompareMethod.Text) + 1, DropDownList1.Text, ",") - 1)
c = Mid(DropDownList1.Text, _
InStr(InStr(1, DropDownList1.Text, ",", CompareMethod.Text) + 1, DropDownList1.Text, ",") + 1, _
Len(DropDownList1.Text))
但是,当我调试它时:
x=18(我使用的字符串是正确的)
y=42(也正确)
z=46(正确)
a=string1(是的!)
c=string3(再次是的!)
和 b=string2,string3 ----->这里发生了什么?
你能告诉我的代码有什么问题吗?我只是不明白