String compare in ASP by using StrComp function

We 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
string1="Plus2net.com"
string2="plus2net.com"
Response.Write StrComp(string1,string2,0)

For different values of string1 and string2 with two values of comparetype the output we will get is given here in a table.

string1string2comparetypeOutput
Plus2net.complus2net.com0-1
Plus2net.complus2net.com10
Plus2net.comPlus2net.com00
Plus2net.comPlus2net.com10
plus2net.comPlus2net.com01
plus2net.comPlus2net.com10

Be the first to post comment on this article :





Further readings
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

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer