CompareInfo.IsSuffix Metode

Definisi

Menentukan apakah string diakhiri dengan akhiran tertentu.

Overload

IsSuffix(String, String)

Menentukan apakah string sumber yang ditentukan diakhiri dengan akhiran yang ditentukan.

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

Menentukan apakah rentang karakter baca-saja diakhiri dengan akhiran tertentu.

IsSuffix(String, String, CompareOptions)

Menentukan apakah string sumber yang ditentukan diakhiri dengan akhiran yang ditentukan menggunakan nilai yang ditentukan CompareOptions .

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

Menentukan apakah string diakhiri dengan akhiran tertentu.

IsSuffix(String, String)

Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs

Menentukan apakah string sumber yang ditentukan diakhiri dengan akhiran yang ditentukan.

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

Parameter

source
String

String untuk dicari.

suffix
String

String untuk dibandingkan dengan akhir .source

Mengembalikan

true jika panjang suffix kurang dari atau sama dengan panjang source dan source berakhir dengan suffix; jika tidak, false.

Pengecualian

sourceadalah null.

-atau-

suffixadalah null.

Contoh

Contoh berikut menentukan apakah string adalah awalan atau akhiran string lain.

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

Keterangan

Setiap string dimulai dan diakhir dengan substring kosong (""); oleh karena itu, jika suffix adalah string kosong, metode ini mengembalikan true.

Catatan

Jika memungkinkan, Anda harus memanggil metode perbandingan string yang memiliki parameter jenis CompareOptions untuk menentukan jenis perbandingan yang diharapkan. Sebagai aturan umum, gunakan opsi linguistik (menggunakan budaya saat ini) untuk membandingkan string yang ditampilkan di antarmuka pengguna dan tentukan CompareOptions.Ordinal atau CompareOptions.OrdinalIgnoreCase untuk perbandingan keamanan.

Lihat juga

Berlaku untuk

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

Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs

Menentukan apakah rentang karakter baca-saja diakhiri dengan akhiran tertentu.

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

Parameter

source
ReadOnlySpan<Char>

Rentang karakter baca-saja untuk dicari di dalamnya.

suffix
ReadOnlySpan<Char>

Akhiran untuk mencoba mencocokkan di akhir source.

options
CompareOptions

Kombinasi opsional nilai CompareOptions enumerasi untuk digunakan selama kecocokan. Nilai defaultnya adalah None.

Mengembalikan

true jika suffix terjadi di akhir source; jika tidak, false.

Pengecualian

options berisi kombinasi bendera yang tidak didukung.

Berlaku untuk

IsSuffix(String, String, CompareOptions)

Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs

Menentukan apakah string sumber yang ditentukan diakhiri dengan akhiran yang ditentukan menggunakan nilai yang ditentukan 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

Parameter

source
String

String untuk dicari.

suffix
String

String untuk dibandingkan dengan akhir .source

options
CompareOptions

Nilai yang menentukan bagaimana source dan suffix harus dibandingkan. optionsadalah nilai Ordinal enumerasi yang digunakan sendiri, atau kombinasi bitwise dari satu atau beberapa nilai berikut: IgnoreCase, , IgnoreSymbols, IgnoreNonSpaceIgnoreWidth, dan IgnoreKanaType.

Mengembalikan

true jika panjang suffix kurang dari atau sama dengan panjang source dan source berakhir dengan suffix; jika tidak, false.

Pengecualian

sourceadalah null.

-atau-

suffixadalah null.

options berisi nilai yang tidak valid CompareOptions .

Contoh

Contoh berikut menentukan apakah string adalah awalan atau akhiran string lain menggunakan 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

Keterangan

Setiap string dimulai dan diakhir dengan substring kosong (""); oleh karena itu, jika suffix adalah string kosong, metode ini mengembalikan true.

Nilai CompareOptions.StringSort tidak valid untuk metode ini.

Catatan

Jika memungkinkan, Anda harus memanggil metode perbandingan string yang memiliki parameter jenis CompareOptions untuk menentukan jenis perbandingan yang diharapkan. Sebagai aturan umum, gunakan opsi linguistik (menggunakan budaya saat ini) untuk membandingkan string yang ditampilkan di antarmuka pengguna dan tentukan CompareOptions.Ordinal atau CompareOptions.OrdinalIgnoreCase untuk perbandingan keamanan.

Lihat juga

Berlaku untuk

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

Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs
Sumber:
CompareInfo.cs

Menentukan apakah string diakhiri dengan akhiran tertentu.

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

Parameter

source
ReadOnlySpan<Char>

Rentang karakter baca-saja untuk dicari di dalamnya.

suffix
ReadOnlySpan<Char>

Rentang karakter baca-saja yang berisi akhiran untuk mencoba mencocokkan di akhir source.

options
CompareOptions

untuk CompareOptions digunakan selama kecocokan.

matchLength
Int32

Ketika metode ini kembali, berisi jumlah karakter source yang cocok dengan akhiran yang diinginkan. Ini mungkin berbeda dari panjang jika perbandingan suffix linguistik dilakukan. Atur ke 0 jika akhiran tidak cocok.

Mengembalikan

true jika suffix terjadi di akhir source; jika tidak, false.

Pengecualian

options berisi kombinasi bendera yang tidak didukung.

Keterangan

Metode ini memiliki overhead yang lebih besar daripada kelebihan beban lain IsSuffix(String, String, CompareOptions) yang tidak mengambil matchLength argumen. Panggil kelebihan beban ini hanya jika Anda memerlukan informasi panjang kecocokan.

Berlaku untuk