CompareInfo.IsSuffix Metoda

Definice

Určuje, zda řetězec končí konkrétní příponou.

Přetížení

IsSuffix(String, String)

Určuje, zda zadaný zdrojový řetězec končí zadanou příponou.

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

Určuje, zda rozsah znaků jen pro čtení končí konkrétní příponou.

IsSuffix(String, String, CompareOptions)

Určuje, jestli zadaný zdrojový řetězec končí zadanou příponou pomocí zadané CompareOptions hodnoty.

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

Určuje, zda řetězec končí konkrétní příponou.

IsSuffix(String, String)

Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs

Určuje, zda zadaný zdrojový řetězec končí zadanou příponou.

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

Parametry

source
String

Řetězec, ve který se má hledat.

suffix
String

Řetězec, který se má porovnat s koncem .source

Návraty

true pokud je délka menší suffix nebo rovna délce source a source končí na suffix; v opačném případě false.

Výjimky

source je null.

-nebo-

suffix je null.

Příklady

Následující příklad určuje, jestli je řetězec předponou nebo příponou jiného řetězce.

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

Poznámky

Každý řetězec začíná a končí prázdným podřetězcem (""); Proto pokud suffix je prázdný řetězec, tato metoda vrátí true.

Poznámka

Pokud je to možné, měli byste volat metody porovnávání řetězců, které mají parametr typu CompareOptions , abyste určili druh očekávaného porovnání. Obecně platí, že pro porovnávání řetězců zobrazených v uživatelském rozhraní a zadání nebo CompareOptions.OrdinalIgnoreCase pro porovnání zabezpečení používejte CompareOptions.Ordinal jazykové možnosti (s použitím aktuální jazykové verze).

Viz také

Platí pro

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

Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs

Určuje, zda rozsah znaků jen pro čtení končí konkrétní příponou.

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

Parametry

source
ReadOnlySpan<Char>

Rozsah znaků jen pro čtení, ve které se má hledat.

suffix
ReadOnlySpan<Char>

Přípona, která se má pokusit o shodu na konci .source

options
CompareOptions

Volitelná kombinace hodnot výčtu CompareOptions , které se mají použít během shody. Výchozí hodnota je None.

Návraty

true pokud suffix se objeví na konci , sourcejinak hodnota false.

Výjimky

options obsahuje nepodporovanou kombinaci příznaků.

Platí pro

IsSuffix(String, String, CompareOptions)

Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs

Určuje, jestli zadaný zdrojový řetězec končí zadanou příponou pomocí zadané CompareOptions hodnoty.

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

Parametry

source
String

Řetězec, ve který se má hledat.

suffix
String

Řetězec, který se má porovnat s koncem .source

options
CompareOptions

Hodnota, která definuje, jak source a suffix má být porovnána. options je buď hodnota Ordinal výčtu používaná sama o sobě, nebo bitové kombinace jedné nebo více následujících hodnot: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidtha IgnoreKanaType.

Návraty

true pokud je délka menší suffix nebo rovna délce source a source končí na suffix; v opačném případě false.

Výjimky

source je null.

-nebo-

suffix je null.

options obsahuje neplatnou CompareOptions hodnotu.

Příklady

Následující příklad pomocí určuje, jestli je řetězec předponou nebo příponou jiného řetězce.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

Poznámky

Každý řetězec začíná a končí prázdným podřetězcem (""); Proto pokud suffix je prázdný řetězec, tato metoda vrátí true.

Hodnota CompareOptions.StringSort není pro tuto metodu platná.

Poznámka

Pokud je to možné, měli byste volat metody porovnávání řetězců, které mají parametr typu CompareOptions , abyste určili druh očekávaného porovnání. Obecně platí, že pro porovnávání řetězců zobrazených v uživatelském rozhraní a zadání nebo CompareOptions.OrdinalIgnoreCase pro porovnání zabezpečení používejte CompareOptions.Ordinal jazykové možnosti (s použitím aktuální jazykové verze).

Viz také

Platí pro

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

Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs
Zdroj:
CompareInfo.cs

Určuje, zda řetězec končí konkrétní příponou.

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

Parametry

source
ReadOnlySpan<Char>

Rozsah znaků jen pro čtení, ve které se má hledat.

suffix
ReadOnlySpan<Char>

Rozsah znaků jen pro čtení obsahující příponu, která se má pokusit o shodu na konci .source

options
CompareOptions

Hodnota CompareOptions , která se má použít během shody.

matchLength
Int32

Když tato metoda vrátí, obsahuje počet znaků source , které odpovídají požadované příponě. Tato délka se může lišit od délky suffix , pokud se provede lingvistické porovnání. Pokud se přípona neshodovala, nastavte na hodnotu 0.

Návraty

true pokud suffix se objeví na konci , sourcejinak hodnota false.

Výjimky

options obsahuje nepodporovanou kombinaci příznaků.

Poznámky

Tato metoda má větší režii než jiná IsSuffix(String, String, CompareOptions) přetížení, která nepřebírají matchLength argument. Volání tohoto přetížení pouze v případě, že požadujete informace o délce shody.

Platí pro