String compare in ASP by using StrComp functionWe can compare two strings by using built in ASP function StrComp(). We can also specify different way of comparison by adding a third optional value in comparison. Here is the syntax of StrComp function.
StrComp(string1, string2, comparetype )
string1 and string2 are two string variables we are comparing, the value of comparetype ( Optional ) can be either 1 or 0. By default it is set to 0. If comparetype is set to 1 then lower case and upper case text are treated as same. If comparetype is set to 0 then ( or not entered ) then binary comparison is done so upper case letters comes before the lower case letter.
The output of the StrComp function gives output 0 if both the compared strings are equal and gives -1 if string1 is less than string2. It gives output 1 if string1 is greater than string2.
Here is the code for StrComp function comparing two strings.
For different values of string1 and string2 with two values of comparetype the output we will get is given here in a table.
Be the first to post comment on this article :
ASP functions to handle string|
Adding two or more strings in ASP
Getting the size or length of the string by using len() function
Removing blank space before and after a string using trim function
Changing lower to upper or upper to lower case of text present inside a string
Reversing a string variable by using StrReverse function
Compare two strings in different ways by using StrComp function
Collecting parts from Left , right and middle areas of a string
Checking matching of a string inside another string using InStr function
Searching and replacing strings inside another string using Replace function
Creating arrays by splitting string using split() function
Joining elements of an array to create a string variable
Line Break by replacing text line break to html line break using Replace function