我需要在文件中找到一个字符串的绝对出现。
我无法在下面使用:
System.IO.File.ReadAllText("D:\asdf\def.txt").IndexOf("string_to_search")
答案 0 :(得分:0)
这将有效:
System.IO.File.ReadAllText("D:\asdf\def.txt").IndexOf("I_LOVE_INDIA")
如果您希望在查找“I_LOVE_INDIA_TOO”时失败,那么您需要检查,例如:
Dim s as String = System.IO.File.ReadAllText("D:\asdf\def.txt")
Dim success as Boolean = CheckStringContainsILoveIndia(s)
Public Function CheckStringContainsILoveIndia(Byval s as String) as Boolean
Dim success as Boolean = False
If s.IndexOf("I_LOVE_INDIA_TOO") == -1 AND s.IndexOf("I_LOVE_INDIA") > -1 Then
success = True
End If
return success
End Sub