Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除字符以在文本框中保留3个数字,vb.net_Vb.net - Fatal编程技术网

删除字符以在文本框中保留3个数字,vb.net

删除字符以在文本框中保留3个数字,vb.net,vb.net,Vb.net,我正试图从网站上阅读的一行文字中删除所有多余的字符 “1.TMI为xxx,提醒操作员包括TMI编号” 我希望删除除代表数字的三个“xxx”之外的所有内容 我考虑过一个数组,但结果是在文本框的左开始处出现了“1” 谢谢,詹姆斯你可以试试这个: 假设您将文本放入字符串中 Dim WebText as String = <source here> Dim c As Integer = WebText.Length Dim x As Integer Dim Output As Integer

我正试图从网站上阅读的一行文字中删除所有多余的字符

“1.TMI为xxx,提醒操作员包括TMI编号”

我希望删除除代表数字的三个“xxx”之外的所有内容

我考虑过一个数组,但结果是在文本框的左开始处出现了“1”

谢谢,詹姆斯你可以试试这个:

假设您将文本放入字符串中

Dim WebText as String = <source here>
Dim c As Integer = WebText.Length
Dim x As Integer
Dim Output As Integer

For x = 0 To c - 1
    If Not (x + 2) >= c Then
        If Char.IsNumber(WebText.Chars(x)) AndAlso Char.IsNumber(WebText.Chars(x + 1)) AndAlso Char.IsNumber(WebText.Chars(x + 2)) Then
            Output = CInt(CStr(WebText.Chars(x).ToString & WebText.Chars(x + 1).ToString & WebText.Chars(x + 2).ToString))
            Exit For
        End If
    End If
Next
MessageBox.Show(Output.ToString) 'Displaying it in a MessageBox
Dim WebText作为字符串=
Dim c作为整数=WebText.Length
作为整数的Dim x
将输出设置为整数
对于x=0到c-1
如果不是(x+2)>=c,则
如果Char.IsNumber(WebText.Chars(x))和also Char.IsNumber(WebText.Chars(x+1))和also Char.IsNumber(WebText.Chars(x+2)),那么
输出=CInt(CStr(WebText.Chars(x).ToString和WebText.Chars(x+1).ToString和WebText.Chars(x+2).ToString))
退出
如果结束
如果结束
下一个
Show(Output.ToString)'在MessageBox中显示它

或者如ZeroWorks所说,如果您更喜欢正则表达式:

Dim WebText As String = <source here>
Dim RgEx As Regex = New Regex("[0-9]{3}")
Dim m As Match = RgEx.Match(WebText)
Dim Output As Integer

If m.Success Then
    Dim g As Group = m.Groups(1)
    Output = CInt(g.ToString())
End If
Dim WebText作为字符串=
Dim RgEx As Regex=New Regex(“[0-9]{3}”)
Dim m As Match=RgEx.Match(WebText)
将输出设置为整数
如果m.成功了那么
尺寸g作为组=m.组(1)
输出=CInt(g.ToString())
如果结束
请注意:我自己还没有尝试过此代码。:)

那么

Dim Input = "1.TMI IS xxx AND OPERATORS ARE REMINDED TO INCLUDE THE TMI NUMBER"

Dim StringValue = Input.
    Split("."c).
    Skip(1).
    First.
    Split(" "c).
    Skip(2).
    First

Dim Number = Integer.Parse(StringValue)

它将取第一个
后面的第三个单词,并将其解析为整数

您可以使用正则表达式来完成此操作。。。它更简单、干净、智能。简单的单行代码?yourText=Regex.Replace(str,“[\d-]{3}”,String.Empty)Edit:Dim result As String=Regex.Match(yourText,[\d-]{3}”).value您对每个字符都检查了三次,虽然它的性能可能优于正则表达式,但它的可读性令人噩梦