我很困惑這里發生了什么:
Dim sSearchIn As String = "Bla"
Dim sSearchFor As String = Vb6ChrW(65533) 'This results in the string "?"
Dim i As Integer = sSearchIn.IndexOf(sSearchFor, 0)
我希望 "i" 為 -1,因為字串 "?" 不存在于字串 "Bla" 中。
但是,“i”是 0。
我錯過了什么?
謝謝!
Public Function Vb6ChrW(ByVal uKeyCode As Integer) As String
Dim nChar As Char = Char.ConvertFromUtf32(uKeyCode)
Return New String(nChar, 1)
End Function
uj5u.com熱心網友回復:
您正在執行文化敏感搜索。它的行為如記錄:
在文化敏感搜索中,如果
value包含可忽略的字符,則結果等同于洗掉該字符進行搜索。如果 value 僅包含一個或多個可忽略字符,則該IndexOf(String, Int32)方法始終回傳startIndex
如果你想要一個字符代碼級別的搜索,你應該使用
sSearchIn.IndexOf(sSearchFor, StringComparison.Ordinal)
,如您所料,給出 -1。
您還應該轉動Option Strict On,以便它正確地制動您Vb6ChrW最初不需要的功能,因為ChrW存在。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494159.html
上一篇:操作JSON節點以具有[]括號
