CompareInfo.IsSuffix CompareInfo.IsSuffix CompareInfo.IsSuffix CompareInfo.IsSuffix Method

Definição

Determina se uma cadeia de caracteres começa com um sufixo específico.Determines whether a string ends with a specific suffix.

Sobrecargas

IsSuffix(String, String) IsSuffix(String, String) IsSuffix(String, String) IsSuffix(String, String)

Determina se a cadeia de caracteres de origem especificada termina com o prefixo especificado.Determines whether the specified source string ends with the specified suffix.

IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions)

Determina se a cadeia de caracteres de origem determinada termina com o sufixo especificado usando o valor CompareOptions especificado.Determines whether the specified source string ends with the specified suffix using the specified CompareOptions value.

IsSuffix(String, String) IsSuffix(String, String) IsSuffix(String, String) IsSuffix(String, String)

Determina se a cadeia de caracteres de origem especificada termina com o prefixo especificado.Determines whether the specified source string ends with the specified suffix.

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

Parâmetros

source
String String String String

A cadeia de caracteres a ser pesquisada.The string to search in.

suffix
String String String String

A cadeia de caracteres a ser comparada com o final de source.The string to compare with the end of source.

Retornos

true se o tamanho de suffix for menor ou igual ao tamanho de source e source terminar com suffix; caso contrário, false.true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.

Exceções

source é null.source is null.

- ou --or- suffix é null.suffix is null.

Exemplos

O exemplo a seguir determina se uma cadeia de caracteres é o prefixo ou sufixo de outra cadeia de caracteres.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
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 'Main 

End Class 'SamplesCompareInfo


'This code produces the following output.
'
'IsPrefix( calle, lle ) : False
'IsPrefix( llegar, lle ) : True
'IsSuffix( calle, lle ) : True
'IsSuffix( llegar, lle ) : False

Comentários

Cada cadeia de caracteres começa e termina com uma subcadeia de caracteres vazia (""); Portanto, se suffix é uma cadeia de caracteres vazia, este método retorna true.Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

Observação

Quando possível, você deve chamar cadeia de caracteres de métodos de comparação que têm um parâmetro de tipo CompareOptions para especificar o tipo de comparação esperado.When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. Como regra geral, use opções linguísticas (usando a cultura atual) para comparar cadeias de caracteres exibidas na interface do usuário e especifique CompareOptions.Ordinal ou CompareOptions.OrdinalIgnoreCase para comparações de segurança.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.

Veja também

IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions) IsSuffix(String, String, CompareOptions)

Determina se a cadeia de caracteres de origem determinada termina com o sufixo especificado usando o valor CompareOptions especificado.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 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

Parâmetros

source
String String String String

A cadeia de caracteres a ser pesquisada.The string to search in.

suffix
String String String String

A cadeia de caracteres a ser comparada com o final de source.The string to compare with the end of source.

options
CompareOptions CompareOptions CompareOptions CompareOptions

Um valor que define como source e suffix devem ser comparados.A value that defines how source and suffix should be compared. options é o valor da enumeração Ordinal usado por si só ou a combinação bit a bit de um ou mais dos seguintes valores: 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.

Retornos

true se o tamanho de suffix for menor ou igual ao tamanho de source e source terminar com suffix; caso contrário, false.true if the length of suffix is less than or equal to the length of source and source ends with suffix; otherwise, false.

Exceções

source é null.source is null.

- ou --or- suffix é null.suffix is null.

options contém um valor CompareOptions inválido.options contains an invalid CompareOptions value.

Exemplos

O exemplo a seguir determina se uma cadeia de caracteres é o prefixo ou sufixo de outra cadeia de caracteres usando 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
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 'Main 

End Class 'SamplesCompareInfo


'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

Comentários

Cada cadeia de caracteres começa e termina com uma subcadeia de caracteres vazia (""); Portanto, se suffix é uma cadeia de caracteres vazia, este método retorna true.Every string starts and ends with an empty substring (""); therefore, if suffix is an empty string, this method returns true.

O CompareOptions.StringSort valor não é válido para esse método.The CompareOptions.StringSort value is not valid for this method.

Observação

Quando possível, você deve chamar cadeia de caracteres de métodos de comparação que têm um parâmetro de tipo CompareOptions para especificar o tipo de comparação esperado.When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. Como regra geral, use opções linguísticas (usando a cultura atual) para comparar cadeias de caracteres exibidas na interface do usuário e especifique CompareOptions.Ordinal ou CompareOptions.OrdinalIgnoreCase para comparações de segurança.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.

Veja também

Aplica-se a