When is an "Apple" not an "apple"? Well in VBScript,
case matters and "Apple" does not equal "apple"! When you compare them
you'll get False! While this is extremely useful if you care about case,
when you don't it's not so useful.
There are a couple ways to compare strings while ignoring their case.
The first is the good old string comparison function, StrComp. It takes 3
parameters. The first two are the two strings to compare ant the third is
a value indicating how to compare them. This can be either
vbBinaryCompare (0) or vbTextCompare (1). The default is binary, but for
a case insensitive comparison you'll want to use vbTextCompare like this:
Note: strComp doesn't return a boolean as you might expect. Instead, it
returns -1 if the first value is smaller, a 0 if they're equal,
a 1 if the second value is smaller, or Null if either input is Null.
You can also accomplish a case insensitive comparison by simply
converting both values to all lower or upper case using LCase or UCase like this:
<%= LCase("Apple") = LCase("apple") %>
So you see... comparing "Apples" to "apples" really isn't all that hard. Just don't
get me started with those pesky oranges! ;)
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.