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.
Dim string1,string2
For different values of string1 and string2 with two values of comparetype the output we will get is given here in a table.
|
string1 | string2 | comparetype | Output |
Plus2net.com | plus2net.com | 0 | -1 |
Plus2net.com | plus2net.com | 1 | 0 |
Plus2net.com | Plus2net.com | 0 | 0 |
Plus2net.com | Plus2net.com | 1 | 0 |
plus2net.com | Plus2net.com | 0 | 1 |
plus2net.com | Plus2net.com | 1 | 0 |
Be the first to post comment on this article :