Syntax |
StrComp(string1,string2 [,compare]) |
|||
Description |
Returns an Integer indicating the result of comparing the two string arguments. |
|||
Comments |
Any of the following values are returned: |
|||
|
0 |
string1 = string2 |
||
|
1 |
string1 > string2 |
||
|
1 |
string1 < string2 |
||
|
NULL |
string1 or string2 is Null |
||
|
|
The StrComp function accepts the following parameters: |
||
|
Parameter |
Description |
||
|
string1 |
First string to be compared, which can be any expression convertible to a String. |
||
|
string2 |
Second string to be compared, which can be any expression convertible to a String. |
||
|
compare |
Optional Integer specifying how the comparison is to be performed. It can be either of the following values: |
||
|
|
|
0 |
Case-sensitive comparison |
|
|
|
1 |
Case-insensitive comparison |
|
If compareis not specified, then the current Option Compare setting is used. If no Option Compare statement has been encountered, then Binary is used (that is, string comparison is case-sensitive). |
|||
Example |
This example compares two strings and displays the results. It illustrates that the function compares two strings to the length of the shorter string in determining equivalency. Const crlf = Chr$(13) + Chr$(10) Sub Main() Dim abc As Integer Dim abi As Integer Dim cdc As Integer Dim cdi As Integer a$ = "This string is UPPERCASE and lowercase" b$ = "This string is uppercase and lowercase" c$ = "This string" d$ = "This string is uppercase and lowercase characters" msg1 = "a = " & a & crlf msg1 = msg1 & "b = " & b & crlf msg1 = msg1 & "c = " & c & crlf msg1 = msg1 & "d = " & d & crlf & crlf abc = StrComp(a$,b$,1) msg1 = msg1 & "a and c (insensitive) : " & abc & crlf abi = StrComp(a$,b$,0) msg1 = msg1 & "a and c (sensitive): " & abi & crlf cdc = StrComp(c$,d$,1) msg1 = msg1 & "c and d (insensitive): " & cdc & crlf cdi = StrComp(c$,d$,0) msg1 = msg1 & "c and d (sensitive) : " & cdi & crlf MsgBox msg1 End Sub |
|||
See Also |
Comparison Operators (topic); Like (operator); Option Compare (statement). |
|||
|
|
|
|
|
S |