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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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?

QUICK TIP:
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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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