1

この質問で申し訳ありません。私は従来の ASP にかなり慣れていないため、理解できません。

一連の郵便番号の開始を含む変数があります。

strPostCode = "HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8,HS9,IV41,IV42" etc etc

ここで、ユーザーが入力した郵便番号がその文字列に存在するかどうかを確認する必要があります。

したがって、「HS2 4AB」、「HS2」、「HS24AB」はすべて一致を返す必要があります。

何か案は?

ありがとう

4

2 に答える 2

1

郵便番号をコンマで分割してから、1 つずつ移動して一致を探す必要があります。

コードは次のようになります。

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、上記のコードで言及されている代替行を使用します。

于 2013-02-20T09:58:30.933 に答える
0

検索文字列を文字に分割し、その文字が文字列に存在するかどうかをループチェックすることができます。コードについて申し訳ありません-錆びていますが、私が言っていることがわかると思います...

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
于 2013-02-19T22:24:31.597 に答える