你能在VBScript字符串中关闭区分大小写吗?

Dan*_*n W 2 vbscript asp-classic

我很确定答案是否定的.我知道我可以写

如果lcase(strFoo)= lcase(request.querystring("x"))则...

或者使用inStr,但我只想检查是否有一些未记录的设置隐藏在注册表中或某处使VBScript字符串的内容与脚本语言的其余部分保持一致!

谢谢丹

Mik*_*nry 10

有一个StrComp函数允许通过vbTextCompare作为第三个参数传递对两个字符串进行不区分大小写的比较.主要文档并没有那么明显,但是在这篇Hey,Scripting Guy文章中对它进行了讨论.

例如:

If StrComp(strFoo, Request.QueryString("x"), vbTextCompare) = 0 Then ...
Run Code Online (Sandbox Code Playgroud)

但是,在实践中,我使用LCase或者UCase方式不仅仅是StrComp不区分大小写的字符串比较,因为它对我来说更明显.


EBG*_*een 5

否.根据功能,选项可能在那里(例如InStr)作为可选参数,但是为了直接比较,没有全局选项.

可以使用的一个鲜为人知的选项是,如果您有一个字符串列表,并且您想查看字符串是否在该列表中:

Dim dicList : Set dicList = CreateObject("Scripting.Dictionary")
Dim strTest

dicList.CompareMode = 0 ' Binary ie case sensitive
dicList.Add "FOO", ""
dicList.Add "BAR", ""
dicList.Add "Wombat", ""

strTest = "foo"
WScript.Echo CStr(dicList.Exists(strTest))

Set dicList = CreateObject("Scripting.Dictionary")
dicList.CompareMode = 1 ' Text ie case insensitive
dicList.Add "FOO", ""
dicList.Add "BAR", ""
dicList.Add "Wombat", ""

strTest = "foo"
WScript.Echo CStr(dicList.Exists(strTest))
Run Code Online (Sandbox Code Playgroud)