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)

來源:
CompareInfo.cs
來源:
CompareInfo.cs
來源:
CompareInfo.cs

判斷指定的來源字串是否以指定字尾結束。

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 的結尾相比較的字串。

傳回

如果 suffix 的長度小於或等於 source 的長度,且 source 是以 suffix 結束,則為 true,否則為 false

例外狀況

sourcenull

-或-

suffixnull

範例

下列範例會判斷字串是否為另一個字串的前置詞或後綴。

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.OrdinalCompareOptions.OrdinalIgnoreCase 進行安全性比較。

另請參閱

適用於

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

來源:
CompareInfo.cs
來源:
CompareInfo.cs
來源:
CompareInfo.cs

判斷唯讀字元範圍是否以特定字尾結束。

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

傳回

suffix 出現在 source 的結尾,則為 true;否則為 false

例外狀況

options 包含旗標不支持的組合。

適用於

IsSuffix(String, String, CompareOptions)

來源:
CompareInfo.cs
來源:
CompareInfo.cs
來源:
CompareInfo.cs

使用指定的 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

值,這個值會定義應該如何比較 sourcesuffixoptions 若不是本身所使用的 Ordinal 列舉值,就是下列一個或多個值的位元組合:IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType

傳回

如果 suffix 的長度小於或等於 source 的長度,且 source 是以 suffix 結束,則為 true,否則為 false

例外狀況

sourcenull

-或-

suffixnull

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.OrdinalCompareOptions.OrdinalIgnoreCase 進行安全性比較。

另請參閱

適用於

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

來源:
CompareInfo.cs
來源:
CompareInfo.cs
來源:
CompareInfo.cs

判斷字串是否以特定字尾結束。

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。

傳回

suffix 出現在 source 的結尾,則為 true;否則為 false

例外狀況

options 包含旗標不支持的組合。

備註

這個方法的額外負荷大於 IsSuffix(String, String, CompareOptions) 其他不採用 matchLength 自變數的多載。 只有在您需要相符長度資訊時,才呼叫此多載。

適用於