Strings.StrComp(String, String, CompareMethod) Yöntem
Tanım
Dize karşılaştırmasının sonucuna bağlı olarak-1, 0 veya 1 döndürür.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
Parametreler
- String1
- String
Gereklidir.Required. Herhangi bir geçerli String ifade.Any valid String expression.
- String2
- String
Gereklidir.Required. Herhangi bir geçerli String ifade.Any valid String expression.
- Compare
- CompareMethod
İsteğe bağlı.Optional. Dize karşılaştırma türünü belirtir.Specifies the type of string comparison. CompareAtlanırsa, Option Compare ayar karşılaştırma türünü belirler.If Compare is omitted, the Option Compare setting determines the type of comparison.
Döndürülenler
Aşağıdaki değerlerden biri:One of the following values:
| EğerIf | StrComp dönüşlerStrComp returns |
|---|---|
String1 önce sıralar String2String1 sorts ahead of String2 | -1-1 |
String1 Şuna eşittir String2String1 is equal to String2 | 00 |
String1 sonra sıralar String2String1 sorts after String2 | 11 |
Özel durumlar
Compare değer geçerli değil.Compare value is not valid.
Örnekler
Bu örnek, StrComp bir dize karşılaştırmasının sonuçlarını döndürmek için işlevini kullanır.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)
Açıklamalar
Dizeler, ilk karakterle başlayan Alfasayısal sıralama değerleriyle karşılaştırılır.The strings are compared by alphanumeric sort values beginning with the first character. İkili karşılaştırmalar, metinsel karşılaştırmalar ve sıralama düzeni hakkında daha fazla bilgi için bkz. Option Compare deyimin.For further information on binary comparisons, textual comparisons, and sort order, see Option Compare Statement.
CompareBağımsız değişken ayarları şunlardır:The Compare argument settings are:
| SabitConstant | DescriptionDescription |
|---|---|
Binary |
Karakterlerin iç ikili gösterimlerine göre türetilmiş bir sıralama düzeni temelinde ikili bir karşılaştırma gerçekleştirir.Performs a binary comparison, based on a sort order derived from the internal binary representations of the characters. |
Text |
Sisteminizin değeri tarafından belirlenen büyük/küçük harf duyarsız metin sıralama sırasına göre bir metin karşılaştırması gerçekleştirir LocaleID .Performs a text comparison, based on a case-insensitive text sort order determined by your system's LocaleID value. |