views:

1570

answers:

3

Hi,

I'm pretty sure the answer to this is no. I know that I can write

if lcase(strFoo) = lcase(request.querystring("x")) then...

or use inStr, but I just want to check there isn't some undocumented setting buried in the registry or somewhere that makes the content of VBScript strings behave consistently with the rest of the scripting language!

Thanks Dan

A: 

I doubt the existence of such an option since if there were something like that and you use it, you'll lose the ability to compare strings in a case sensitive manner.

Mehrdad Afshari
+2  A: 

No. Depending on the function the option may be there (InStr for example) as an optional parameter, but for just straight comparison, there is no global option.

One little known option that can be handy is if you have a list of strings and you want to see if a string is in that list:

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))
EBGreen
+3  A: 

There is a StrComp function which allows performing a case-insensitive comparison of two strings by passing vbTextCompare as the third argument. The main documentation doesn't make that obvious, but it is discussed in this Hey, Scripting Guy article.

For example:

If StrComp(strFoo, Request.QueryString("x"), vbTextCompare) = 0 Then ...

However, in practice, I use LCase or UCase way more than StrComp for case-insensitive string comparisons because it's more obvious to me.

Mike Henry
pass in `0` for vbTextCompare (or leave the 3rd argument out) for binary (case sensitive) compare; pass in `1` for textual (case insensitive) compare
JohnB