CompareInfo.IsPrefix Methode

Definition

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Präfix beginnt.

Überlädt

IsPrefix(String, String)

Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Präfix beginnt.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Bestimmt, ob eine schreibgeschützte Zeichenspanne mit einem bestimmten Präfix beginnt.

IsPrefix(String, String, CompareOptions)

Bestimmt mithilfe des angegebenen CompareOptions-Werts, ob die angegebene Quellzeichenfolge mit dem angegebenen Präfix beginnt.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Präfix beginnt.

IsPrefix(String, String)

Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs

Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Präfix beginnt.

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

Parameter

source
String

Die zu durchsuchende Zeichenfolge.

prefix
String

Die Zeichenfolge, die mit dem Anfang von source verglichen werden soll.

Gibt zurück

true, wenn die Länge von prefix kleiner oder gleich der Länge von source ist und source mit prefix beginnt, andernfalls false.

Ausnahmen

source ist null.

- oder -

prefix ist null.

Beispiele

Im folgenden Beispiel wird bestimmt, ob eine Zeichenfolge das Präfix oder Suffix einer anderen Zeichenfolge ist.

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

Hinweise

Jede Zeichenfolge beginnt und endet mit einer leeren Teilzeichenfolge (""); prefix Wenn also eine leere Zeichenfolge ist, gibt diese Methode zurück true.

Hinweis

Wenn möglich, sollten Sie Zeichenfolgenvergleichsmethoden aufrufen, die über einen Parameter vom Typ CompareOptions verfügen, um die art des erwarteten Vergleichs anzugeben. Verwenden Sie in der Regel linguistische Optionen (unter Verwendung der aktuellen Kultur), um Zeichenfolgen zu vergleichen, die auf der Benutzeroberfläche angezeigt werden, und geben Sie CompareOptions.Ordinal oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.

Weitere Informationen

Gilt für:

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs

Bestimmt, ob eine schreibgeschützte Zeichenspanne mit einem bestimmten Präfix beginnt.

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

Parameter

source
ReadOnlySpan<Char>

Die schreibgeschützte Zeichenspanne, die durchsucht werden soll.

prefix
ReadOnlySpan<Char>

Das Präfix, das am Anfang von source abgeglichen werden soll.

options
CompareOptions

Eine optionale Kombination aus CompareOptions-Enumerationswerten, die während des Abgleichs verwendet werden sollen. Der Standardwert ist None.

Gibt zurück

true, wenn prefix am Anfang von source auftritt, andernfalls false.

Ausnahmen

options enthält eine nicht unterstützte Flagkombination.

Gilt für:

IsPrefix(String, String, CompareOptions)

Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs

Bestimmt mithilfe des angegebenen CompareOptions-Werts, ob die angegebene Quellzeichenfolge mit dem angegebenen Präfix beginnt.

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

Parameter

source
String

Die zu durchsuchende Zeichenfolge.

prefix
String

Die Zeichenfolge, die mit dem Anfang von source verglichen werden soll.

options
CompareOptions

Ein Wert, der definiert, wie source und prefix verglichen werden sollen. options ist entweder der allein verwendete Enumerationswert Ordinal oder a bitweise Kombination eines oder mehrerer der folgenden Werte: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth und IgnoreKanaType.

Gibt zurück

true, wenn die Länge von prefix kleiner oder gleich der Länge von source ist und source mit prefix beginnt, andernfalls false.

Ausnahmen

source ist null.

- oder -

prefix ist null.

options enthält einen ungültigen CompareOptions-Wert.

Beispiele

Im folgenden Beispiel wird mithilfe CompareOptionsvon bestimmt, ob eine Zeichenfolge das Präfix oder Suffix einer anderen Zeichenfolge ist.

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

Hinweise

Jede Zeichenfolge beginnt und endet mit einer leeren Teilzeichenfolge (""); prefix Wenn also eine leere Zeichenfolge ist, gibt diese Methode zurück true.

Der CompareOptions.StringSort Wert ist für diese Methode ungültig.

Hinweis

Wenn möglich, sollten Sie Zeichenfolgenvergleichsmethoden aufrufen, die über einen Parameter vom Typ CompareOptions verfügen, um die art des erwarteten Vergleichs anzugeben. Verwenden Sie in der Regel linguistische Optionen (unter Verwendung der aktuellen Kultur), um Zeichenfolgen zu vergleichen, die auf der Benutzeroberfläche angezeigt werden, und geben Sie CompareOptions.Ordinal oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.

Weitere Informationen

Gilt für:

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs
Quelle:
CompareInfo.cs

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Präfix beginnt.

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

Parameter

source
ReadOnlySpan<Char>

Die schreibgeschützte Zeichenspanne, die durchsucht werden soll.

prefix
ReadOnlySpan<Char>

Die schreibgeschützte Zeichenspanne, die das Präfix enthält, mit dem versucht wird, eine Entsprechung am Anfang von source zu ermitteln.

options
CompareOptions

Die bei der Übereinstimmung zu verwendenden CompareOptions.

matchLength
Int32

In der Rückgabe dieser Methode ist die Anzahl der Zeichen aus source enthalten, die mit dem gewünschten Präfix übereinstimmen. Dies kann sich von der Länge von prefix unterscheiden, wenn ein linguistischer Vergleich durchgeführt wird. Wird auf 0 festgelegt, wenn das Präfix nicht übereinstimmt.

Gibt zurück

true, wenn prefix am Anfang von source auftritt, andernfalls false.

Ausnahmen

options enthält eine nicht unterstützte Flagkombination.

Hinweise

Diese Methode hat einen höheren Mehraufwand als andere IsPrefix(String, String, CompareOptions) Überladungen, die kein Argument annehmen matchLength . Rufen Sie diese Überladung nur auf, wenn Sie die Informationen zur Übereinstimmungslänge benötigen.

Gilt für: