我有2个字符串:
string1 =“3122§3121§152KL§256§6598J§65974§3256§6982”
string2 = “3256”
我需要检查确切的string2是否在string1
中如果我寻找“256”,结果必须为负,只有我寻找“3256”
提前感谢所有帮助
答案 0 :(得分:0)
使用InStr:
InStr(start, string_var, string_part, comparetype)
示例:
string1="3122§3121§152KL§256§6598J§65974§3256§6982"
string2= "3256"
Response.Write InStr(string1,string2)
start和comparetype是可选的Argument
答案 1 :(得分:0)
InStr()
不会给您完全匹配,最好使用Array
。
Dim string1: string1 = "3122§3121§152KL§256§6598J§65974§3256§6982"
Dim string2: string2 = "3256"
Dim data: data = Split(string1, "§")
Dim value
Dim is_match: is_match = False
For Each value In data
If StrComp(value, string2, vbTextCompare) = 0 Then
'Flag we have a match and exit loop.
is_match = True
Exit For
End If
Next