次の形式の 46 文字の文字列を含むテキスト ボックス (DropDownList1) があります。
(文字列1、文字列2、文字列3)
このように、コンマなしで文字列値を取得したい:
a=文字列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 ----->何が起こったのですか?
私のコードの何が問題なのか教えてください。私は単にそれを取得しません