SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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
Further readings
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
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.