CompareInfo.IsSuffix Methode

Definition

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Suffix endet.

Überlädt

IsSuffix(String, String)

Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix endet.

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

Bestimmt, ob eine schreibgeschützte Zeichenspanne mit einem bestimmten Suffix endet.

IsSuffix(String, String, CompareOptions)

Bestimmt mithilfe des angegebenenCompareOptions-Werts, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix endet.

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

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Suffix endet.

IsSuffix(String, String)

Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix endet.

public:
 virtual bool IsSuffix(System::String ^ source, System::String ^ suffix);
public:
 bool IsSuffix(System::String ^ source, System::String ^ suffix);
public virtual bool IsSuffix (string source, string suffix);
public bool IsSuffix (string source, string suffix);
abstract member IsSuffix : string * string -> bool
override this.IsSuffix : string * string -> bool
member this.IsSuffix : string * string -> bool
Public Overridable Function IsSuffix (source As String, suffix As String) As Boolean
Public Function IsSuffix (source As String, suffix As String) As Boolean

Parameter

source
String

Die zu durchsuchende Zeichenfolge.

suffix
String

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

Gibt zurück

Boolean

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

Ausnahmen

source ist null.

- oder -

suffix 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 (""); Wenn suffix es sich um eine leere Zeichenfolge handelt, gibt diese Methode daher truezurück.

Hinweis

Wenn möglich, sollten Sie Zeichenfolgenvergleichsmethoden aufrufen, die über einen Parameter des Typs CompareOptions verfügen, um die Art des Vergleichs anzugeben, die erwartet wird. Verwenden Sie in der Regel linguistische Optionen (mit der aktuellen Kultur), um Zeichenfolgen zu vergleichen, die in der Benutzeroberfläche angezeigt werden, und geben CompareOptions.Ordinal Oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.

Siehe auch

Gilt für

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

Bestimmt, ob eine schreibgeschützte Zeichenspanne mit einem bestimmten Suffix endet.

public bool IsSuffix (ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.IsSuffix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions -> bool
Public Function IsSuffix (source As ReadOnlySpan(Of Char), suffix 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.

suffix
ReadOnlySpan<Char>

Das Suffix, das am Ende 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

Boolean

true, wenn suffix am Ende von source auftritt, andernfalls false.

Ausnahmen

options enthält eine nicht unterstützte Flagkombination.

Gilt für

IsSuffix(String, String, CompareOptions)

Bestimmt mithilfe des angegebenenCompareOptions-Werts, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix endet.

public:
 virtual bool IsSuffix(System::String ^ source, System::String ^ suffix, System::Globalization::CompareOptions options);
public:
 bool IsSuffix(System::String ^ source, System::String ^ suffix, System::Globalization::CompareOptions options);
public virtual bool IsSuffix (string source, string suffix, System.Globalization.CompareOptions options);
public bool IsSuffix (string source, string suffix, System.Globalization.CompareOptions options);
abstract member IsSuffix : string * string * System.Globalization.CompareOptions -> bool
override this.IsSuffix : string * string * System.Globalization.CompareOptions -> bool
member this.IsSuffix : string * string * System.Globalization.CompareOptions -> bool
Public Overridable Function IsSuffix (source As String, suffix As String, options As CompareOptions) As Boolean
Public Function IsSuffix (source As String, suffix As String, options As CompareOptions) As Boolean

Parameter

source
String

Die zu durchsuchende Zeichenfolge.

suffix
String

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

options
CompareOptions

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

Gibt zurück

Boolean

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

Ausnahmen

source ist null.

- oder -

suffix ist null.

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

Beispiele

Im folgenden Beispiel wird bestimmt, ob eine Zeichenfolge das Präfix oder Suffix einer anderen Zeichenfolge ist 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

Hinweise

Jede Zeichenfolge beginnt und endet mit einer leeren Teilzeichenfolge (""); Wenn suffix es sich um eine leere Zeichenfolge handelt, gibt diese Methode daher truezurück.

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

Hinweis

Wenn möglich, sollten Sie Zeichenfolgenvergleichsmethoden aufrufen, die über einen Parameter des Typs CompareOptions verfügen, um die Art des Vergleichs anzugeben, die erwartet wird. Verwenden Sie in der Regel linguistische Optionen (mit der aktuellen Kultur), um Zeichenfolgen zu vergleichen, die in der Benutzeroberfläche angezeigt werden, und geben CompareOptions.Ordinal Oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.

Siehe auch

Gilt für

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

Bestimmt, ob eine Zeichenfolge mit einem angegebenen Suffix endet.

public:
 bool IsSuffix(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, System::Globalization::CompareOptions options, [Runtime::InteropServices::Out] int % matchLength);
public bool IsSuffix (ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, System.Globalization.CompareOptions options, out int matchLength);
member this.IsSuffix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions * int -> bool
Public Function IsSuffix (source As ReadOnlySpan(Of Char), suffix 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.

suffix
ReadOnlySpan<Char>

Die schreibgeschützte Zeichenspanne, die das Suffix enthält, mit dem versucht wird, eine Entsprechung am Ende 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 Suffix übereinstimmen. Dies kann sich von der Länge von suffix unterscheiden, wenn ein linguistischer Vergleich durchgeführt wird. Wird auf 0 festgelegt, wenn das Suffix nicht übereinstimmt.

Gibt zurück

Boolean

true, wenn suffix am Ende von source auftritt, andernfalls false.

Ausnahmen

options enthält eine nicht unterstützte Flagkombination.

Hinweise

Diese Methode hat mehr Aufwand als andere IsSuffix(String, String, CompareOptions) Überladungen, die kein Argument übernehmen matchLength . Rufen Sie diese Überladung nur auf, wenn Sie die Übereinstimmungslängeninformationen benötigen.

Gilt für