在文本框中查找整数值

时间:2019-03-20 09:10:59

标签: vb.net

我需要一点帮助。如果在文本框中-TxtStringNum1.Text-我们有数字3和TxtIntDraws.Lines(1)-包含以下集合:13,20,21,23,47,49,50,51,63,64,66,70 它告诉我存在3的数字,但实际上是13的数字。它不能整体上查找它。

Private Sub ScanareLinia1()
    Dim textsrtring As String = TxtStringNum1.Text
    Dim words As String() = textsrtring.Split(New Char() {" "c})
    ' Split string based on space
    Dim found As Boolean = False
    ' Use For Each loop over words
    Dim word As Integer
    For Each word In words
        For i As Integer = 0 To TxtIntDraws.Lines.Count - 1
            If TxtIntDraws.Lines(1).Contains(word) Then
                TxtResultStr1.Text = word
            End If
        Next
    Next
    ScanareLinia2()
End Sub

我有一个比较好的代码,但是我不知道如何在上面的代码中使用它。

 Private Sub CompareNumbers()
        'Pentru funcția de Check-In (For Match Exactly Value Number in List)
        'First Textbox that is to be used for compare
        Dim textBox1Numbers As List(Of Integer) = GetNumbersFromTextLine(TxtStringNum1.Text)
        'Second Textbox that is to be used for compare
        Dim textBox2Numbers As List(Of Integer) = GetNumbersFromTextLine(TxtbValBeforeCompar.Text)
        'Union List of Common Numbers (this uses a lambda expression, it can be done using two For Each loops instead.)
        Dim commonNumbers As List(Of Integer) = textBox1Numbers.Where(Function(num) textBox2Numbers.Contains(num)).ToList()
        'This is purely for testing to see if it worked you can.
        Dim sb As StringBuilder = New StringBuilder()
        For Each foundNum As Integer In commonNumbers
            sb.Append(foundNum.ToString()).Append(TextBox25.Text)
            TxtbValAfterCompar.Text = (sb.ToString())
        Next
    End Sub

    Private Function GetNumbersFromTextLine(ByVal sTextLine As String) As List(Of Integer)
        'Pentru funcția de Check-In (For Match Exactly Value Number in List)
        Dim numberList As List(Of Integer) = New List(Of Integer)()
        Dim sSplitNumbers As String() = sTextLine.Split(TextBox8.Text)
        For Each sNumber As String In sSplitNumbers
            If IsNumeric(sNumber) Then
                Dim iNum As Integer = CInt(sNumber)
                TxtbValAfterCompar.Text = iNum
                If Not numberList.Contains(iNum) Then
                    TxtbValAfterCompar.Text = ("")
                    numberList.Add(iNum)
                End If
            Else
            End If
        Next
        Return numberList
    End Function

1 个答案:

答案 0 :(得分:0)

您可以使用String.SplitArray.IndexOf使用以下条件:

If Array.IndexOf(TxtIntDraws.Lines(1).Split(","c), CStr(word)) > -1 Then
    TxtResultStr1.Text = word
End If

所以后面的Array.IndexOf(CStr("13,14,15,16,17").Split(","c), "13") > -1True,而Array.IndexOf(CStr("13,14,15,16,17").Split(","c), "3") > -1False