CompareInfo.IsSuffix Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Bestimmt, ob eine Zeichenfolge mit einem bestimmten Suffix endet.
Überlädt
| Name | Beschreibung |
|---|---|
| IsSuffix(String, String) |
Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix endet. |
| IsSuffix(String, String, CompareOptions) |
Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix mit dem angegebenen CompareOptions Wert 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 virtual bool IsSuffix(string source, string suffix);
abstract member IsSuffix : string * string -> bool
override this.IsSuffix : string * string -> bool
Public Overridable Function IsSuffix (source As String, suffix As String) As Boolean
Parameter
- source
- String
Die zu durchsuchende Zeichenfolge.
- suffix
- String
Die zu vergleichende Zeichenfolge mit dem Ende von source.
Gibt zurück
truewenn die Länge suffix kleiner oder gleich der Länge von source und source endet mit suffix; andernfalls . false
Ausnahmen
Beispiele
Im folgenden Beispiel wird ermittelt, ob eine Zeichenfolge das Präfix oder Suffix einer anderen Zeichenfolge ist.
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 zurück true.
Note
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 CompareOptions.Ordinal Oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.
Weitere Informationen
Gilt für:
IsSuffix(String, String, CompareOptions)
Bestimmt, ob die angegebene Quellzeichenfolge mit dem angegebenen Suffix mit dem angegebenen CompareOptions Wert endet.
public:
virtual bool IsSuffix(System::String ^ source, System::String ^ suffix, System::Globalization::CompareOptions options);
public virtual 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
Public Overridable Function IsSuffix (source As String, suffix As String, options As CompareOptions) As Boolean
Parameter
- source
- String
Die zu durchsuchende Zeichenfolge.
- suffix
- String
Die zu vergleichende Zeichenfolge mit dem Ende von source.
- options
- CompareOptions
Ein Wert, der definiert, wie source und suffix wie verglichen werden soll.
optionsist entweder der von sich selbst verwendete Enumerationswert Ordinal oder die bitweise Kombination aus einem oder mehreren der folgenden Werte: IgnoreCase, , , IgnoreNonSpaceIgnoreSymbols, IgnoreWidthund IgnoreKanaType.
Gibt zurück
truewenn die Länge suffix kleiner oder gleich der Länge von source und source endet mit suffix; andernfalls . false
Ausnahmen
options enthält einen ungültigen CompareOptions Wert.
Beispiele
Im folgenden Beispiel wird ermittelt, ob es sich bei einer Zeichenfolge um das Präfix oder Suffix einer anderen Zeichenfolge handelt.CompareOptions
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 zurück true.
Die Werte und CompareOptions.StringSort Werte CompareOptions.NumericOrdering sind für diese Methode ungültig.
Note
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 CompareOptions.Ordinal Oder CompareOptions.OrdinalIgnoreCase für Sicherheitsvergleiche an.