CompareInfo.IsSuffix 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定字符串是否以特定后缀结尾。
重载
| 名称 | 说明 |
|---|---|
| IsSuffix(String, String) |
确定指定的源字符串是否以指定的后缀结尾。 |
| IsSuffix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions) |
确定字符的只读范围是否以特定的后缀结尾。 |
| IsSuffix(String, String, CompareOptions) |
确定指定的源字符串是否使用指定的值以指定的 CompareOptions 后缀结尾。 |
| IsSuffix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32) |
确定字符串是否以特定后缀结尾。 |
IsSuffix(String, String)
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- 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字符串。
返回
true 如果长度 suffix 小于或等于 source 长度和 source 结尾,则为 suffix;否则为 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)
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- 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。
返回
true 如果在 suffix 结尾 source处发生,则为 ;否则为 false。
例外
options 包含不受支持的标志组合。
适用于
IsSuffix(String, String, CompareOptions)
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- 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
一个值,用于定义如何 source 和 suffix 应进行比较。
options是自身使用的枚举值,或者是以下一个或多个值的Ordinal按位组合:IgnoreCase、、IgnoreSymbolsIgnoreNonSpace、IgnoreWidth和IgnoreKanaType。
返回
true 如果长度 suffix 小于或等于 source 长度和 source 结尾,则为 suffix;否则为 false。
例外
options 包含无效 CompareOptions 值。
示例
下面的示例确定字符串是另一个字符串 CompareOptions的前缀还是后缀。
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.NumericOrdering 的和 CompareOptions.StringSort 值无效。
注释
如果可能,应调用具有类型 CompareOptions 参数的字符串比较方法,以指定预期的比较类型。 作为一般规则,对于在用户界面中显示的字符串比较,请使用语言选项(使用当前文化)并指定 CompareOptions.Ordinal 或 CompareOptions.OrdinalIgnoreCase 用于安全比较。
另请参阅
适用于
IsSuffix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- 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。
返回
true 如果在 suffix 结尾 source处发生,则为 ;否则为 false。
例外
options 包含不受支持的标志组合。
注解
此方法的开销比不采用matchLength参数的其他IsSuffix(String, String, CompareOptions)重载要高。 仅当需要匹配长度信息时调用此重载。