StrComp: Difference between revisions
Jump to navigation
Jump to search
Created page with "STRCOMP(''string1'', ''string2''[, ''compare'']) '''Description''' STRCOMP compares two strings and returns an integer value which indicates the alphabetical relationship be..." |
|||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.'' | |||
''' | StrComp(''string1'', ''string2''[, ''compare'']) | ||
== Description == | |||
''' | StrComp compares two strings and returns an integer value which indicates the alphabetical relationship between them. The required parameters, ''string1'' and ''string2'', are two valid string expressions. The optional parameter, ''compare'', is used to specify the type of comparison performed. StrComp returns -1 if ''string1'' is less than ''string2'', 0 if ''string1'' is equal to ''string2'', or 1 if ''string1'' is greater than ''string2''. | ||
'''Table: Comparison constants''' | |||
{| class="wikitable" | |||
|- | |||
! Constant !! Value !! Description | |||
|- | |||
| vbBinaryCompare || 0 || Binary comparison case sensitive (default) | |||
|- | |||
| vbTextCompare || 1 || Textual comparison, case insensitive | |||
|} | |||
== Example (BASIC) == | |||
<pre> | <pre> | ||
Rem StrComp Example | |||
' | 'StrComp compares two strings | ||
Sort "Kenny", "Kyle", vbBinaryCompare | Sort "Kenny", "Kyle", vbBinaryCompare | ||
Sort "Eric", "eric", vbTextCompare | Sort "Eric", "eric", vbTextCompare | ||
Sort "Wendy", "Stan", vbBinaryCompare | Sort "Wendy", "Stan", vbBinaryCompare | ||
Sub Sort(string1, string2, compare) | |||
Dim Order | |||
Order = | Order = StrComp(string1, string2, compare) | ||
If Order < 0 Then | |||
Print string1 & " precedes " & string2 | |||
ElseIf Order > 0 Then | |||
Print string2 & " precedes " & string1 | |||
Else | |||
Print string1 & " and " & string2 _ | |||
& " are equivalent" | & " are equivalent" | ||
End If | |||
End Sub | |||
</pre> | </pre> | ||
== Output == | |||
<pre> | <pre> | ||
Line 34: | Line 47: | ||
Stan precedes Wendy | Stan precedes Wendy | ||
</pre> | </pre> | ||
[[Category:Language Reference]] | |||
[[Category:Strings]] | |||
[[Category:BASIC Functions]] |
Latest revision as of 15:36, 25 March 2019
This function is for BASIC compatibility. It is not available in pure JavaScript projects.
StrComp(string1, string2[, compare])
Description
StrComp compares two strings and returns an integer value which indicates the alphabetical relationship between them. The required parameters, string1 and string2, are two valid string expressions. The optional parameter, compare, is used to specify the type of comparison performed. StrComp returns -1 if string1 is less than string2, 0 if string1 is equal to string2, or 1 if string1 is greater than string2.
Table: Comparison constants
Constant | Value | Description |
---|---|---|
vbBinaryCompare | 0 | Binary comparison case sensitive (default) |
vbTextCompare | 1 | Textual comparison, case insensitive |
Example (BASIC)
Rem StrComp Example 'StrComp compares two strings Sort "Kenny", "Kyle", vbBinaryCompare Sort "Eric", "eric", vbTextCompare Sort "Wendy", "Stan", vbBinaryCompare Sub Sort(string1, string2, compare) Dim Order Order = StrComp(string1, string2, compare) If Order < 0 Then Print string1 & " precedes " & string2 ElseIf Order > 0 Then Print string2 & " precedes " & string1 Else Print string1 & " and " & string2 _ & " are equivalent" End If End Sub
Output
Kenny precedes Kyle Eric and eric are equivalent Stan precedes Wendy