ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
An Overview of ASP.NET
Connections, Commands, And Procedures
What is ASP?

How to Debug an ASP Project with Visual Studio .NET
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Comparing Strings in VBScript

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:

Response.Write strComp("Apple", "apple", vbTextCompare)
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!   ;)

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers