经典ASP-尝试在另一个字符串变量中搜索一个字符串. (替代InStr函数) [英] Classic ASP - Trying to search a string in another string variable. (Alternative to InStr function)

查看:96
本文介绍了经典ASP-尝试在另一个字符串变量中搜索一个字符串. (替代InStr函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码currentregion = 'BC'Regions = 'ABC'中.

我正在尝试在Regions中找到currentregion,通常因为if条件为false,它应该会按else.

I am trying to find the currentregion in the Regions and normally it should hit else as the if condition is false.

但是它返回true,因为InStr搜索部分字符串而不是字符串vs字符串.因此,BC是ABC的一部分,因此进入if循环.

But it returns true as InStr searches part of the string not string vs string. So BC being part of ABC it enters the if loop.

Classic ASP中有一个函数,我可以将字符串与字符串进行比较,但不能像InStr函数那样将字符串作为字符串的一部分.

Is there a function in Classic ASP that I can compare a string to string but not part of the string like InStr function.

RegionSQL = "SELECT * FROM Regions Where Auth <= " & Session("U_Auth") & ";"                
Set rsRegion=Server.CreateObject("recordset")
rsRegion.Open RegionSQL,TheDB

If NOT rsRegion.EOF And NOT rsRegion.BOF Then
    rsRegion.MoveFirst
    While Not rsRegion.Eof 
        'Grab Current Region
        currentregion = rsRegion("RegionCodeShort")   

        If InStr(Regions,currentregion) > 0 Then
            checked = "checked"
        Else
            checked = ""
        End If

推荐答案

拆分首先将字符串放入数组,然后遍历并比较每个元素

Split the string into an array first, then loop through and compare each element

这篇关于经典ASP-尝试在另一个字符串变量中搜索一个字符串. (替代InStr函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆