Asp classic 我的字符串部分是否存在于另一个字符串中?

Asp classic 我的字符串部分是否存在于另一个字符串中?,asp-classic,postal-code,Asp Classic,Postal Code,很抱歉这个问题,我对我的经典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 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
Dim strPostCode As String=“HS1、HS2、HS3、HS4、HS5、HS6、HS7、HS8、HS9、IV41、IV42”
将搜索字符串设置为字符串=“HS24AB”
将匹配设置为布尔值=False
作为整数的Dim i
For(i=0;i
您可以将搜索字符串拆分为多个字符,然后在循环中检查字符串中是否存在该字符。很抱歉,代码也生锈了,但我想您可以看到我在说什么

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
Dim strPostCode As String=“HS1、HS2、HS3、HS4、HS5、HS6、HS7、HS8、HS9、IV41、IV42”
将搜索字符串设置为字符串=“HS24AB”
将匹配设置为布尔值=False
作为整数的Dim i
For(i=0;i
您需要用逗号拆分邮政编码,然后逐个查找匹配项

代码如下所示:

Dim stropstcode,strInput,x
暗号,邮政编码,当前邮政编码,blnFoundMatch
strPostCode=“HS1、HS2、HS3、HS4、HS5、HS6、HS7、HS8、HS9、IV41、IV42”
strInput=“HS24AB”
arrPostCodes=Split(strPostCode,“”)
blnFoundMatch=False
对于x=0到UBound(arrPostCodes)
curPostCode=arrPostCodes(x)
'如果左(strInput,Len(curPostCode))=则为curPostCode
如果InStr(strInput,curPostCode)>0,则
blnFoundMatch=True
退出
如果结束
下一个
删除邮政编码
如果blnFoundMatch那么
“找到匹配项,做点什么。。。
如果结束

以上内容将在用户输入的任何位置查找每个邮政编码,例如“4AB HS2”还将返回一个匹配项;如果您希望邮政编码仅出现在输入的开头,请使用上述代码中注释的替代
if
行。

您需要用逗号拆分邮政编码,然后逐个查找匹配项

代码如下所示:

Dim stropstcode,strInput,x
暗号,邮政编码,当前邮政编码,blnFoundMatch
strPostCode=“HS1、HS2、HS3、HS4、HS5、HS6、HS7、HS8、HS9、IV41、IV42”
strInput=“HS24AB”
arrPostCodes=Split(strPostCode,“”)
blnFoundMatch=False
对于x=0到UBound(arrPostCodes)
curPostCode=arrPostCodes(x)
'如果左(strInput,Len(curPostCode))=则为curPostCode
如果InStr(strInput,curPostCode)>0,则
blnFoundMatch=True
退出
如果结束
下一个
删除邮政编码
如果blnFoundMatch那么
“找到匹配项,做点什么。。。
如果结束

以上内容将在用户输入的任何位置查找每个邮政编码,例如“4AB HS2”还将返回一个匹配项;如果您希望邮政编码仅出现在输入的开头,请使用上面代码中注释的替代
if
行。

我选择了注释掉的替代行,使用了一个treat谢谢!干杯,很高兴我能帮上忙!我选择了注释掉的替代行,使用了t谢谢!干杯,很高兴我能帮忙!