CompareInfo.IsSuffix Метод

Определение

Определяет, заканчивается ли строка указанным суффиксом.

Перегрузки

IsSuffix(String, String)

Определяет, заканчивается ли указанная строка источника указанным суффиксом.

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

Определяет, заканчивается ли доступный только для чтения диапазон символов указанным суффиксом.

IsSuffix(String, String, CompareOptions)

Определяет, заканчивается ли указанная строка источника указанным суффиксом, с использованием заданного значения CompareOptions.

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

Определяет, заканчивается ли строка указанным суффиксом.

IsSuffix(String, String)

Определяет, заканчивается ли указанная строка источника указанным суффиксом.

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

Параметры

source
String

Строка, в которой выполняется поиск.

suffix
String

Строка, сравниваемая с концом source.

Возвращаемое значение

Boolean

true, если длина suffix меньше или равна длине source и source заканчивается suffix; в противном случае — false.

Исключения

source имеет значение null.

-или-

suffix имеет значение null.

Примеры

В следующем примере определяется, является ли строка префиксом или суффиксом другой строки.

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

Комментарии

Каждая строка начинается и заканчивается пустой подстрокой (""). таким образом, если suffix это пустая строка, этот метод возвращает true.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа CompareOptions , чтобы указать ожидаемый тип сравнения. Как правило, используйте языковые параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

См. также раздел

Применяется к

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

Определяет, заканчивается ли доступный только для чтения диапазон символов указанным суффиксом.

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

Параметры

source
ReadOnlySpan<Char>

Доступный только для чтения диапазон символов, в котором выполняется поиск.

suffix
ReadOnlySpan<Char>

Суффикс, который используется для проверки на соответствие в конце source.

options
CompareOptions

Необязательное сочетание значений перечисления CompareOptions, используемое во время проверки на соответствие. Значение по умолчанию — None.

Возвращаемое значение

Boolean

true, если suffix присутствует в конце source; в противном случае — false.

Исключения

options содержит неподдерживаемое сочетание флагов.

Применяется к

IsSuffix(String, String, CompareOptions)

Определяет, заканчивается ли указанная строка источника указанным суффиксом, с использованием заданного значения CompareOptions.

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

Параметры

source
String

Строка, в которой выполняется поиск.

suffix
String

Строка, сравниваемая с концом source.

options
CompareOptions

Значение, определяющее способ сравнения source и suffix. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Boolean

true, если длина suffix меньше или равна длине source и source заканчивается suffix; в противном случае — false.

Исключения

source имеет значение null.

-или-

suffix имеет значение null.

options содержит недопустимое значение CompareOptions.

Примеры

В следующем примере определяется, является ли строка префиксом или суффиксом другой строки с помощью 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

Комментарии

Каждая строка начинается и заканчивается пустой подстрокой (""). таким образом, если suffix это пустая строка, этот метод возвращает true.

Недопустимое CompareOptions.StringSort значение для этого метода.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа CompareOptions , чтобы указать ожидаемый тип сравнения. Как правило, используйте языковые параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

См. также раздел

Применяется к

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

Определяет, заканчивается ли строка указанным суффиксом.

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

Параметры

source
ReadOnlySpan<Char>

Доступный только для чтения диапазон символов, в котором выполняется поиск.

suffix
ReadOnlySpan<Char>

Диапазон символов только для чтения, содержащий суффикс для проверки на соответствие в конце source.

options
CompareOptions

CompareOptions для использования при сопоставлении.

matchLength
Int32

При возврате этот метод содержит число символов из source, которые совпали с нужным суффиксом. Совпадения могут иметь разную с suffix длину, если было выполнено лингвистическое сравнение. Задайте значение 0, если суффикс не совпал.

Возвращаемое значение

Boolean

true, если suffix присутствует в конце source; в противном случае — false.

Исключения

options содержит неподдерживаемое сочетание флагов.

Комментарии

Этот метод имеет большую нагрузку, чем другие IsSuffix(String, String, CompareOptions) перегрузки, которые не принимают matchLength аргумент. Вызовите эту перегрузку только в том случае, если требуются сведения о длине соответствия.

Применяется к