StrComp: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "STRCOMP(''string1'', ''string2''[, ''compare'']) '''Description''' STRCOMP compares two strings and returns an integer value which indicates the alphabetical relationship be..."
 
Brendon (talk | contribs)
No edit summary
Line 1: Line 1:
STRCOMP(''string1'', ''string2''[, ''compare''])
StrComp(''string1'', ''string2''[, ''compare''])


'''Description'''
== 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.
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.


'''Example'''
== Example ==


<pre>
<pre>
REM STRCOMP Example
Rem StrComp Example
'STRCOMP compares two strings
'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)
Sub Sort(string1, string2, compare)
   DIM Order
   Dim Order
   Order = STRCOMP(string1, string2, compare)
   Order = StrComp(string1, string2, compare)
   IF Order < 0 THEN
   If Order < 0 Then
     PRINT string1 & " precedes " & string2
     Print string1 & " precedes " & string2
   ELSEIF Order > 0 THEN
   ElseIf Order > 0 Then
     PRINT string2 & " precedes " & string1
     Print string2 & " precedes " & string1
   ELSE
   Else
     PRINT string1 & " and " & string2 _
     Print string1 & " and " & string2 _
       & " are equivalent"
       & " are equivalent"
   END IF
   End If
END SUB
End Sub
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 34: Line 34:
Stan precedes Wendy
Stan precedes Wendy
</pre>
</pre>
[[Category:Language Reference]]

Revision as of 03:34, 17 August 2012

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.

Example

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