Strings.StrComp(String, String, CompareMethod) Metoda
Definice
Vrátí hodnotu-1, 0 nebo 1 na základě výsledku porovnání řetězců.Returns -1, 0, or 1, based on the result of a string comparison.
public static int StrComp (string? String1, string? String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static int StrComp (string String1, string String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member StrComp : string * string * Microsoft.VisualBasic.CompareMethod -> int
Public Function StrComp (String1 As String, String2 As String, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As Integer
Parametry
- String1
- String
Povinná hodnota.Required. Libovolný platný String výraz.Any valid String expression.
- String2
- String
Povinná hodnota.Required. Libovolný platný String výraz.Any valid String expression.
- Compare
- CompareMethod
Nepovinný parametr.Optional. Určuje typ porovnání řetězců.Specifies the type of string comparison. Pokud Compare je tento parametr vynechán, Option Compare nastavení určuje typ porovnání.If Compare is omitted, the Option Compare setting determines the type of comparison.
Návraty
Jedna z následujících hodnot:One of the following values:
| Pokud uživatelIf | Funkce StrComp vrátíStrComp returns |
|---|---|
String1 Seřadí před String2String1 sorts ahead of String2 | -1-1 |
String1 je rovno String2String1 is equal to String2 | 00 |
String1 seřadí za String2String1 sorts after String2 | 11 |
Výjimky
Compare hodnota není platná.Compare value is not valid.
Příklady
Tento příklad používá StrComp funkci k vrácení výsledků porovnání řetězců.This example uses the StrComp function to return the results of a string comparison.
' Defines variables.
Dim testStr1 As String = "ABCD"
Dim testStr2 As String = "abcd"
Dim testComp As Integer
' The two strings sort equally. Returns 0.
testComp = StrComp(testStr1, testStr2, CompareMethod.Text)
' testStr1 sorts before testStr2. Returns -1.
testComp = StrComp(testStr1, testStr2, CompareMethod.Binary)
' testStr2 sorts after testStr1. Returns 1.
testComp = StrComp(testStr2, testStr1, CompareMethod.Binary)
Poznámky
Řetězce jsou porovnány pomocí alfanumerických hodnot řazení začínajících prvním znakem.The strings are compared by alphanumeric sort values beginning with the first character. Další informace o binárních porovnáních, textových porovnání a pořadí řazení naleznete v tématu příkaz Option Compare.For further information on binary comparisons, textual comparisons, and sort order, see Option Compare Statement.
CompareNastavení argumentů jsou:The Compare argument settings are:
| KonstantaConstant | DescriptionDescription |
|---|---|
Binary |
Provede binární porovnání na základě pořadí řazení odvozeného z interní binární reprezentace znaků.Performs a binary comparison, based on a sort order derived from the internal binary representations of the characters. |
Text |
Provádí porovnání textu v závislosti na pořadí řazení textu bez rozlišení velkých a malých písmen určených hodnotou vašeho systému LocaleID .Performs a text comparison, based on a case-insensitive text sort order determined by your system's LocaleID value. |