VBScript: Strings, You Can`t Function without Them - Comparing Strings
(Page 4 of 6 )
You can compare strings in VBScript using StrComp(). It does two types of comparisons, a textual and a binary. Binary is the default. If you want to use binary you can either leave it blank or use 0. If you want textual, use -1. Just a brief note here. "WORD" does equal the same value as "word" in a textual search, but does not equal the same thing in a binary search, so always keep this in mind.
The results returned from a comparison are:
-1: FirstString is less than SecondString
0: FirstString is equal to SecondString
1: FirstString is greater than SecondString
Null: One of the strings has a null value
Here it is at work:
<html>
<body>
<script type="text/vbscript">
document.write(StrComp("Burger King","Burger King")) & "<br/>"
document.write(StrComp("Burger King","Burger King",0))& "<br/>"
document.write(StrComp("Burger King","burger king",0))& "<br/>"
document.write(StrComp("Burger King","Burger King",1))& "<br/>"
document.write(StrComp("Burger King","burger king",1))& "<br/>"
document.write(StrComp("Burger King","McDonald's",0))& "<br/>"
document.write(StrComp("burger king","Burger King",0))& "<br/>"
document.write(StrComp("wendy's","Burger King",1))& "<br/>"
</script>
</body>
</html>
The results:
0
0
-1
0
0
-1
1
1
Next: The String Function >>
More Windows Scripting Articles
More By James Payne