Vbscript StrComp Function To Compare Strings

by top54u.com 03 Aug, 2008
Spotlight.....

Vbscript StrComp string comparison function provides the functionality to compare the two string values. Vbscript StrComp function returns number values such as -1, 0 or 1 based the comparison between the specified string expressions. If both string values specified as parameters of vbscript StrComp function are same then it returns 0. Returned value as 0 means both the string expressions are equal.

 

Syntax for Vbscript StrComp Function

 

StrComp( string1, string2, compare)

 

StrComp function of vbscript accepts 3 types of parameters to compare the strings as shown in the above syntax.

 

  1. string1: first parameter accepts the string type value or vbscript variable name of string type that is to be compared with other string value.


  2. string2: second parameter also accepts the string expression that is to be compared with first string parameter value.


  3. compare: optional. Compare parameter accepts the name of the approach for string comparison. It supports the following two types of vb enum type parameters:

    vbBinaryCompare = 0: for binary comparison approach.
    vbTextCompare = 1: for text comparison approach.

 

 

Expected Results of Vbscript StrComp function

If string1 < string2, strComp returns -1.

If string1 > string2, it returns 1

If string1 = string2, it returns 0

 

Examples of Vbscript StrComp String Comparison Function

 

Example 1:

<%

Dim myString1

Dim myString2

myString1 = "Vbscript StrComp Function"

 

myString2 = "vbscript strcomp function"

 

Response.Write(StrComp(myString1, myString2))

 

%>

 

Output:

-1

 

 

Example 2:

 

<%

Response.Write(StrComp(myString1, myString2, vbTextCompare))

%>

 

Output:

0

 

Example 3:

 

<%

Response.Write(StrComp(myString2, myString1))

%>

 

Output:

1

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:58:09 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....