CompareInfo.IsSuffix Metodo

Definizione

Determina se una stringa termina con un suffisso specifico.Determines whether a string ends with a specific suffix.

Overload

IsSuffix(String, String)

Determina se la stringa di origine specificata termina con il suffisso specificato.Determines whether the specified source string ends with the specified suffix.

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

Determina se un intervallo di caratteri di sola lettura termina con un suffisso specifico.Determines whether a read-only span of characters ends with a specific suffix.

IsSuffix(String, String, CompareOptions)

Determina se la stringa di origine specificata termina con il suffisso specificato usando il valore CompareOptions specificato.Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.

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

Determina se una stringa termina con un suffisso specifico.Determines whether a string ends with a specific suffix.

IsSuffix(String, String)

Determina se la stringa di origine specificata termina con il suffisso specificato.Determines whether the specified source string ends with the specified suffix.

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

Parametri

source
String

Stringa in cui effettuare la ricerca.The string to search in.

suffix
String

Stringa da confrontare con la fine di source.The string to compare with the end of source.

Restituisce

Boolean

true se la lunghezza di suffix è minore o uguale alla lunghezza di source e se source termina con suffix. In caso contrario, false.true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.

Eccezioni

source è null.source is null.

-oppure--or-

suffix è null.suffix is null.

Esempio

Nell'esempio seguente viene determinato se una stringa è il prefisso o il suffisso di un'altra stringa.The following example determines whether a string is the prefix or suffix of another string.

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

Commenti

Ogni stringa inizia e termina con una sottostringa vuota (""); Se pertanto suffix è una stringa vuota, questo metodo restituisce true .Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

Nota

Quando possibile, è necessario chiamare i metodi di confronto tra stringhe con un parametro di tipo CompareOptions per specificare il tipo di confronto previsto.When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. Come regola generale, usare le opzioni linguistiche (usando le impostazioni cultura correnti) per confrontare le stringhe visualizzate nell'interfaccia utente e specificare CompareOptions.Ordinal o CompareOptions.OrdinalIgnoreCase per i confronti di sicurezza.As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

Vedi anche

Si applica a

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

Determina se un intervallo di caratteri di sola lettura termina con un suffisso specifico.Determines whether a read-only span of characters ends with a specific suffix.

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

Parametri

source
ReadOnlySpan<Char>

Intervallo di caratteri di sola lettura in cui eseguire la ricerca.The read-only span of characters to search within.

suffix
ReadOnlySpan<Char>

Suffisso per il quale provare a trovare una corrispondenza alla fine di source.The suffix to attempt to match at the end of source.

options
CompareOptions

Combinazione facoltativa di valori di enumerazione di CompareOptions da usare durante la ricerca della corrispondenza.An optional combination of CompareOptions enumeration values to use during the match. Il valore predefinito è None.The default value is None.

Restituisce

Boolean

true se suffix viene trovato alla fine di source; in caso contrario, false.true if suffix occurs at the end of source; otherwise, false.

Eccezioni

options contiene una combinazione di flag non supportata.options contains an unsupported combination of flags.

Si applica a

IsSuffix(String, String, CompareOptions)

Determina se la stringa di origine specificata termina con il suffisso specificato usando il valore CompareOptions specificato.Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.

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

Parametri

source
String

Stringa in cui effettuare la ricerca.The string to search in.

suffix
String

Stringa da confrontare con la fine di source.The string to compare with the end of source.

options
CompareOptions

Valore che definisce la modalità di confronto di source e suffix.A value that defines how source and suffix should be compared. options è il valore di enumerazione Ordinal utilizzato da solo o la combinazione bit per bit di uno o più dei seguenti valori: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth e IgnoreKanaType.options is either the enumeration value Ordinal used by itself, or the bitwise combination of one or more of the following values: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth, and IgnoreKanaType.

Restituisce

Boolean

true se la lunghezza di suffix è minore o uguale alla lunghezza di source e se source termina con suffix. In caso contrario, false.true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.

Eccezioni

source è null.source is null.

-oppure--or-

suffix è null.suffix is null.

options contiene un valore di CompareOptions non valido.options contains an invalid CompareOptions value.

Esempio

Nell'esempio seguente viene determinato se una stringa è il prefisso o il suffisso di un'altra stringa utilizzando CompareOptions .The following example determines whether a string is the prefix or suffix of another string using 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

Commenti

Ogni stringa inizia e termina con una sottostringa vuota (""); Se pertanto suffix è una stringa vuota, questo metodo restituisce true .Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

Il CompareOptions.StringSort valore non è valido per questo metodo.The CompareOptions.StringSort value is not valid for this method.

Nota

Quando possibile, è necessario chiamare i metodi di confronto tra stringhe con un parametro di tipo CompareOptions per specificare il tipo di confronto previsto.When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. Come regola generale, usare le opzioni linguistiche (usando le impostazioni cultura correnti) per confrontare le stringhe visualizzate nell'interfaccia utente e specificare CompareOptions.Ordinal o CompareOptions.OrdinalIgnoreCase per i confronti di sicurezza.As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

Vedi anche

Si applica a

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

Determina se una stringa termina con un suffisso specifico.Determines whether a string ends with a specific suffix.

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

Parametri

source
ReadOnlySpan<Char>

Intervallo di caratteri di sola lettura in cui eseguire la ricerca.The read-only span of characters to search within.

suffix
ReadOnlySpan<Char>

Intervallo di caratteri di sola lettura contenente il suffisso per tentare di trovare una corrispondenza alla fine di source.The read-only span of characters containing the suffix to attempt to match at the end of source.

options
CompareOptions

Proprietà CompareOptions da usare durante la corrispondenza.The CompareOptions to use during the match.

matchLength
Int32

Quando termina, questo metodo contiene il numero di caratteri di source che corrispondono al suffisso desiderato.When this method returns, contains the number of characters of source that matched the desired suffix. Questo valore può essere diverso dalla lunghezza di suffix se viene eseguito un confronto linguistico.This may be different than the length of suffix if a linguistic comparison is performed. Impostare su 0 se il suffisso non corrisponde.Set to 0 if the suffix did not match.

Restituisce

Boolean

true se suffix viene trovato alla fine di source; in caso contrario, false.true if suffix occurs at the end of source; otherwise, false.

Eccezioni

options contiene una combinazione di flag non supportata.options contains an unsupported combination of flags.

Commenti

Questo metodo presenta un overhead maggiore rispetto ad altri IsSuffix(String, String, CompareOptions) Overload che non accettano un matchLength argomento.This method has greater overhead than other IsSuffix(String, String, CompareOptions) overloads that don't take a matchLength argument. Chiamare questo overload solo se sono necessarie le informazioni sulla lunghezza delle corrispondenze.Call this overload only if you require the match length information.

Si applica a