對不起,對於這個問題,我對我的經典ASP很生疏,無法擺脫困境。我的字符串的部分是否存在於另一個字符串中?
我有一個包含一系列郵政編碼的開始一個變量:
strPostCode = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42" etc etc
現在我需要看看帖子碼的用戶已進入該字符串存在。
所以,「HS2 4AB」,「HS2」,「HS24AB」都需要返回一個匹配項。
任何想法?
感謝
對不起,對於這個問題,我對我的經典ASP很生疏,無法擺脫困境。我的字符串的部分是否存在於另一個字符串中?
我有一個包含一系列郵政編碼的開始一個變量:
strPostCode = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42" etc etc
現在我需要看看帖子碼的用戶已進入該字符串存在。
所以,「HS2 4AB」,「HS2」,「HS24AB」都需要返回一個匹配項。
任何想法?
感謝
你需要用逗號分割後的代碼然後再一個一個地尋找匹配。
代碼看起來是這樣的:
Dim strPostCode, strInput, x
Dim arrPostCodes, curPostCode, blnFoundMatch
strPostCode = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42"
strInput = "HS24AB"
arrPostCodes = Split(strPostCode, ",")
blnFoundMatch = False
For x=0 To UBound(arrPostCodes)
curPostCode = arrPostCodes(x)
'If Left(strInput, Len(curPostCode))=curPostCode Then
If InStr(strInput, curPostCode)>0 Then
blnFoundMatch = True
Exit For
End If
Next
Erase arrPostCodes
If blnFoundMatch Then
'match found, do something...
End If
上面將尋找每個柱代碼在用戶輸入的任何地方例如「4AB HS2」也將返回一個匹配;如果您希望郵政編碼僅出現在輸入的開頭,請使用上述代碼中標註的替代If
行。
你可以,如果該字符的字符串中是否存在搜索字符串分割成字符,然後在一個循環檢查。很抱歉的代碼 - 生鏽過,但我想你可以看到我在說什麼......
Dim strPostCode As String = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42"
Dim SearchString As String = "HS24AB"
Dim Match As Boolean = False
Dim i As Integer
For(i = 0; i< SearchString.Length; i++)
If(strPostCode.Contains(SearchString.charAt(i)) Then
Match = True
Else
Match = False
End If
Next
我去了註釋掉的另一條線,表示感謝! – lunchboxbill 2013-02-20 21:27:00
歡呼,很高興我能幫到你! – 2013-02-20 21:40:35