CompareInfo.IsPrefix Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Określa, czy ciąg rozpoczyna się od określonego prefiksu.
Przeciążenia
IsPrefix(String, String) |
Określa, czy określony ciąg źródłowy rozpoczyna się od określonego prefiksu. |
IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions) |
Określa, czy zakres znaków tylko do odczytu zaczyna się od określonego prefiksu. |
IsPrefix(String, String, CompareOptions) |
Określa, czy określony ciąg źródłowy rozpoczyna się od określonego prefiksu przy użyciu określonej CompareOptions wartości. |
IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32) |
Określa, czy ciąg rozpoczyna się od określonego prefiksu. |
IsPrefix(String, String)
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
Określa, czy określony ciąg źródłowy rozpoczyna się od określonego prefiksu.
public:
virtual bool IsPrefix(System::String ^ source, System::String ^ prefix);
public:
bool IsPrefix(System::String ^ source, System::String ^ prefix);
public virtual bool IsPrefix (string source, string prefix);
public bool IsPrefix (string source, string prefix);
abstract member IsPrefix : string * string -> bool
override this.IsPrefix : string * string -> bool
member this.IsPrefix : string * string -> bool
Public Overridable Function IsPrefix (source As String, prefix As String) As Boolean
Public Function IsPrefix (source As String, prefix As String) As Boolean
Parametry
- source
- String
Ciąg do wyszukania.
- prefix
- String
Ciąg, który ma być porównywany z początkiem ciągu source
.
Zwraca
true
jeśli długość prefix
jest mniejsza lub równa długości source
i source
zaczyna się od prefix
; w przeciwnym razie false
.
Wyjątki
Przykłady
Poniższy przykład określa, czy ciąg jest prefiksem, czy sufiksem innego ciągu.
using namespace System;
using namespace System::Globalization;
int main()
{
// Defines the strings to compare.
String^ myStr1 = "calle";
String^ myStr2 = "llegar";
String^ myXfix = "lle";
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
// Determines whether myXfix is a prefix of S"calle" and S"llegar".
Console::WriteLine( "IsPrefix( {0}, {1}) : {2}", myStr1, myXfix, myComp->IsPrefix( myStr1, myXfix ) );
Console::WriteLine( "IsPrefix( {0}, {1}) : {2}", myStr2, myXfix, myComp->IsPrefix( myStr2, myXfix ) );
// Determines whether myXfix is a suffix of S"calle" and S"llegar".
Console::WriteLine( "IsSuffix( {0}, {1}) : {2}", myStr1, myXfix, myComp->IsSuffix( myStr1, myXfix ) );
Console::WriteLine( "IsSuffix( {0}, {1}) : {2}", myStr2, myXfix, myComp->IsSuffix( myStr2, myXfix ) );
}
/*
This code produces the following output.
IsPrefix(calle, lle) : False
IsPrefix(llegar, lle) : True
IsSuffix(calle, lle) : True
IsSuffix(llegar, lle) : False
*/
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "llegar";
String myXfix = "lle";
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;
// Determines whether myXfix is a prefix of "calle" and "llegar".
Console.WriteLine( "IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix( myStr1, myXfix ) );
Console.WriteLine( "IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix( myStr2, myXfix ) );
// Determines whether myXfix is a suffix of "calle" and "llegar".
Console.WriteLine( "IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix( myStr1, myXfix ) );
Console.WriteLine( "IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix( myStr2, myXfix ) );
}
}
/*
This code produces the following output.
IsPrefix( calle, lle ) : False
IsPrefix( llegar, lle ) : True
IsSuffix( calle, lle ) : True
IsSuffix( llegar, lle ) : False
*/
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "llegar"
Dim myXfix As [String] = "lle"
' Uses the CompareInfo property of the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' Determines whether myXfix is a prefix of "calle" and "llegar".
Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix(myStr1, myXfix))
Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix(myStr2, myXfix))
' Determines whether myXfix is a suffix of "calle" and "llegar".
Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix(myStr1, myXfix))
Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix(myStr2, myXfix))
End Sub
End Class
'This code produces the following output.
'
'IsPrefix( calle, lle ) : False
'IsPrefix( llegar, lle ) : True
'IsSuffix( calle, lle ) : True
'IsSuffix( llegar, lle ) : False
Uwagi
Każdy ciąg rozpoczyna się i kończy pustym podciągem (""); w związku z tym, jeśli prefix
jest ciągiem pustym, ta metoda zwraca wartość true
.
Uwaga
Jeśli to możliwe, należy wywołać metody porównania ciągów, które mają parametr typu CompareOptions , aby określić rodzaj oczekiwanego porównania. Ogólnie rzecz biorąc, użyj opcji językowych (przy użyciu bieżącej kultury) do porównywania ciągów wyświetlanych w interfejsie użytkownika i określenia CompareOptions.Ordinal lub CompareOptions.OrdinalIgnoreCase porównania zabezpieczeń.
Zobacz też
Dotyczy
IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
Określa, czy zakres znaków tylko do odczytu zaczyna się od określonego prefiksu.
public bool IsPrefix (ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), Optional options As CompareOptions = System.Globalization.CompareOptions.None) As Boolean
Parametry
- source
- ReadOnlySpan<Char>
Zakres znaków tylko do odczytu do przeszukiwania.
- prefix
- ReadOnlySpan<Char>
Prefiks do próby dopasowania na początku .source
- options
- CompareOptions
Opcjonalna kombinacja CompareOptions wartości wyliczenia do użycia podczas dopasowywania. Wartość domyślna to None.
Zwraca
true
jeśli prefix
występuje na początku ; source
w przeciwnym razie , false
.
Wyjątki
options
zawiera nieobsługiwaną kombinację flag.
Dotyczy
IsPrefix(String, String, CompareOptions)
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
Określa, czy określony ciąg źródłowy rozpoczyna się od określonego prefiksu przy użyciu określonej CompareOptions wartości.
public:
virtual bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public:
bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public virtual bool IsPrefix (string source, string prefix, System.Globalization.CompareOptions options);
public bool IsPrefix (string source, string prefix, System.Globalization.CompareOptions options);
abstract member IsPrefix : string * string * System.Globalization.CompareOptions -> bool
override this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
member this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
Public Overridable Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean
Public Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean
Parametry
- source
- String
Ciąg do wyszukania.
- prefix
- String
Ciąg, który ma być porównywany z początkiem ciągu source
.
- options
- CompareOptions
Wartość definiująca sposób source
i prefix
elementy, które powinny być porównywane. options
to wartość Ordinalwyliczenia lub bitowa kombinacja co najmniej jednej z następujących wartości: IgnoreCase, , IgnoreSymbolsIgnoreNonSpace, IgnoreWidthi IgnoreKanaType.
Zwraca
true
jeśli długość prefix
jest mniejsza lub równa długości source
i source
zaczyna się od prefix
; w przeciwnym razie false
.
Wyjątki
options
zawiera nieprawidłową CompareOptions wartość.
Przykłady
Poniższy przykład określa, czy ciąg jest prefiksem, czy sufiksem innego ciągu przy użyciu polecenia CompareOptions.
using namespace System;
using namespace System::Globalization;
int main()
{
// Defines the strings to compare.
String^ myStr1 = "calle";
String^ myStr2 = "llegar";
String^ myXfix = "LLE";
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
Console::WriteLine( "IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix );
Console::WriteLine( " With no CompareOptions : {0}", myComp->IsSuffix( myStr1, myXfix ) );
Console::WriteLine( " With None : {0}", myComp->IsSuffix( myStr1, myXfix, CompareOptions::None ) );
Console::WriteLine( " With Ordinal : {0}", myComp->IsSuffix( myStr1, myXfix, CompareOptions::Ordinal ) );
Console::WriteLine( " With IgnoreCase : {0}", myComp->IsSuffix( myStr1, myXfix, CompareOptions::IgnoreCase ) );
Console::WriteLine( "IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix );
Console::WriteLine( " With no CompareOptions : {0}", myComp->IsPrefix( myStr2, myXfix ) );
Console::WriteLine( " With None : {0}", myComp->IsPrefix( myStr2, myXfix, CompareOptions::None ) );
Console::WriteLine( " With Ordinal : {0}", myComp->IsPrefix( myStr2, myXfix, CompareOptions::Ordinal ) );
Console::WriteLine( " With IgnoreCase : {0}", myComp->IsPrefix( myStr2, myXfix, CompareOptions::IgnoreCase ) );
}
/*
This code produces the following output.
IsSuffix "calle", "LLE"
With no CompareOptions : False
With None : False
With Ordinal : False
With IgnoreCase : True
IsPrefix "llegar", "LLE"
With no CompareOptions : False
With None : False
With Ordinal : False
With IgnoreCase : True
*/
using System;
using System.Globalization;
public class SamplesCompareInfo {
public static void Main() {
// Defines the strings to compare.
String myStr1 = "calle";
String myStr2 = "llegar";
String myXfix = "LLE";
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;
Console.WriteLine( "IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix );
Console.WriteLine( " With no CompareOptions : {0}", myComp.IsSuffix( myStr1, myXfix ) );
Console.WriteLine( " With None : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.None ) );
Console.WriteLine( " With Ordinal : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.Ordinal ) );
Console.WriteLine( " With IgnoreCase : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.IgnoreCase ) );
Console.WriteLine( "IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix );
Console.WriteLine( " With no CompareOptions : {0}", myComp.IsPrefix( myStr2, myXfix ) );
Console.WriteLine( " With None : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.None ) );
Console.WriteLine( " With Ordinal : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.Ordinal ) );
Console.WriteLine( " With IgnoreCase : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.IgnoreCase ) );
}
}
/*
This code produces the following output.
IsSuffix "calle", "LLE"
With no CompareOptions : False
With None : False
With Ordinal : False
With IgnoreCase : True
IsPrefix "llegar", "LLE"
With no CompareOptions : False
With None : False
With Ordinal : False
With IgnoreCase : True
*/
Imports System.Globalization
Public Class SamplesCompareInfo
Public Shared Sub Main()
' Defines the strings to compare.
Dim myStr1 As [String] = "calle"
Dim myStr2 As [String] = "llegar"
Dim myXfix As [String] = "LLE"
' Uses the CompareInfo property of the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
Console.WriteLine("IsSuffix ""{0}"", ""{1}""", myStr1, myXfix)
Console.WriteLine(" With no CompareOptions : {0}", myComp.IsSuffix(myStr1, myXfix))
Console.WriteLine(" With None : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.None))
Console.WriteLine(" With Ordinal : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.Ordinal))
Console.WriteLine(" With IgnoreCase : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.IgnoreCase))
Console.WriteLine("IsPrefix ""{0}"", ""{1}""", myStr2, myXfix)
Console.WriteLine(" With no CompareOptions : {0}", myComp.IsPrefix(myStr2, myXfix))
Console.WriteLine(" With None : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.None))
Console.WriteLine(" With Ordinal : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.Ordinal))
Console.WriteLine(" With IgnoreCase : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.IgnoreCase))
End Sub
End Class
'This code produces the following output.
'
'IsSuffix "calle", "LLE"
' With no CompareOptions : False
' With None : False
' With Ordinal : False
' With IgnoreCase : True
'IsPrefix "llegar", "LLE"
' With no CompareOptions : False
' With None : False
' With Ordinal : False
' With IgnoreCase : True
Uwagi
Każdy ciąg rozpoczyna się i kończy pustym podciągem (""); w związku z tym, jeśli prefix
jest ciągiem pustym, ta metoda zwraca wartość true
.
Wartość jest nieprawidłowa CompareOptions.StringSort dla tej metody.
Uwaga
Jeśli to możliwe, należy wywołać metody porównania ciągów, które mają parametr typu CompareOptions , aby określić rodzaj oczekiwanego porównania. Ogólnie rzecz biorąc, użyj opcji językowych (przy użyciu bieżącej kultury) do porównywania ciągów wyświetlanych w interfejsie użytkownika i określenia CompareOptions.Ordinal lub CompareOptions.OrdinalIgnoreCase porównania zabezpieczeń.
Zobacz też
Dotyczy
IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
- Źródło:
- CompareInfo.cs
Określa, czy ciąg rozpoczyna się od określonego prefiksu.
public:
bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System::Globalization::CompareOptions options, [Runtime::InteropServices::Out] int % matchLength);
public bool IsPrefix (ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options, out int matchLength);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions * int -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), options As CompareOptions, ByRef matchLength As Integer) As Boolean
Parametry
- source
- ReadOnlySpan<Char>
Zakres znaków tylko do odczytu do przeszukiwania.
- prefix
- ReadOnlySpan<Char>
Zakres znaków tylko do odczytu zawierający prefiks, który ma być zgodny na początku .source
- options
- CompareOptions
Element CompareOptions do użycia podczas meczu.
- matchLength
- Int32
Gdy ta metoda zwraca wartość , zawiera liczbę znaków source
pasujących do żądanego prefiksu. Może to być inne niż długość prefix
w przypadku przeprowadzenia porównania językowego. Ustaw wartość 0, jeśli prefiks nie jest zgodny.
Zwraca
true
jeśli prefix
występuje na początku ; source
w przeciwnym razie , false
.
Wyjątki
options
zawiera nieobsługiwaną kombinację flag.
Uwagi
Ta metoda ma większe obciążenie niż inne IsPrefix(String, String, CompareOptions) przeciążenia, które nie przyjmują argumentu matchLength
. Wywołaj to przeciążenie tylko wtedy, gdy wymagane są informacje o długości dopasowania.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla