从字符串值 Visual Basic 中提取单独的双精度值。网
Extract separate double values from string value visual basic. Net
我在这里尝试从这个字符串文本“3.6(2.4 到 4.8)”中分别提取双精度值 3.6、2.4、4.8 - 每个都放入一个单独的文本框中
Dim A as string = textbox1.text ' "3.6 (2.4 to 4.8)"
Textbox2.text = value1' 3.6
Textbox3.text = value2' 2.4
Textbox4.text = value3' 4.8
提前致谢:)
一个更新
我搜索并尝试使用此代码
Dim A as string = textbox1.text ' "3.6 (2.4 to 4.8)"
Dim M as Match = Regex.Match(A, "\d+(?:[.,]\d+) *")
If M.Success Then
Dim R1 = M.groups(0).value
Textbox2.text = R1 ' 3.6
但我不知道如何提取其他 2 个值
我写了这段代码,它对我有用:
Dim mc As MatchCollection = Regex.Matches(TextBox1.Text, "\d+(?:[.,]\d+) *")
Dim texts(2) As String ' Specifically assigns for 0, 1, 2 (3 elements)
Dim index As Byte = 0 ' Index increment-er
For Each m As Match In mc
texts(index) = m.ToString ' Writes texts(0... 1... 2...) with m1, m2, m3
index += 1
Next
TextBox2.Text = texts(0) ' Output
TextBox3.Text = texts(1)
TextBox4.Text = texts(2)
我在这里尝试从这个字符串文本“3.6(2.4 到 4.8)”中分别提取双精度值 3.6、2.4、4.8 - 每个都放入一个单独的文本框中
Dim A as string = textbox1.text ' "3.6 (2.4 to 4.8)"
Textbox2.text = value1' 3.6
Textbox3.text = value2' 2.4
Textbox4.text = value3' 4.8
提前致谢:)
一个更新
我搜索并尝试使用此代码
Dim A as string = textbox1.text ' "3.6 (2.4 to 4.8)"
Dim M as Match = Regex.Match(A, "\d+(?:[.,]\d+) *")
If M.Success Then
Dim R1 = M.groups(0).value
Textbox2.text = R1 ' 3.6
但我不知道如何提取其他 2 个值
我写了这段代码,它对我有用:
Dim mc As MatchCollection = Regex.Matches(TextBox1.Text, "\d+(?:[.,]\d+) *")
Dim texts(2) As String ' Specifically assigns for 0, 1, 2 (3 elements)
Dim index As Byte = 0 ' Index increment-er
For Each m As Match In mc
texts(index) = m.ToString ' Writes texts(0... 1... 2...) with m1, m2, m3
index += 1
Next
TextBox2.Text = texts(0) ' Output
TextBox3.Text = texts(1)
TextBox4.Text = texts(2)