vb.net在字符串中搜索搜索

时间:2009-10-28 23:57:45

标签: vb.net

lot_no = "lot123"

s.indexof("lot123") does not return zero

,而

s.indexof(lot_no) returns zero

有没有人见过这样的问题?

包含什么?

    For Each s As String In split1

2 个答案:

答案 0 :(得分:2)

K,看着在你的另一个帖子中添加代码。 当我执行以下代码时,我得到一个结果,我做错了什么?

Public lot__no As String = "<Lot no>928374</Lot no>"
Sub DoSomething()
    Dim temp_string As String = "<beginning of record>ETCETCETC" 
   Dim myDelims As String() = New String() {"<beginning of record>"}
    Dim Split() As String = temp_string.Split(myDelims, StringSplitOptions.None)

    For Each s As String In Split
        If InStr(s, lot__no) <> 0 Then
            Debug.WriteLine("found" + s)
        End If
    Next
End Sub

答案 1 :(得分:1)

不确定你在问什么,但这段代码返回-1 / -1

Dim lotnr As String = "lot123"
For Each s As String In "123asd"
    Debug.WriteLine(s.IndexOf("lot123"))
    Debug.WriteLine(s.IndexOf(lotnr))
Next

使用IndexOf这样:

Dim lotnr As String = "lot123"
For Each s As String In "123asd"
    Debug.WriteLine("lot123".IndexOf(s))
    Debug.WriteLine(lotnr.IndexOf(s))
Next

这会导致: 3 3 4 4 五 五 -1 -1 -1 -1 -1 -1