CompareInfo.IsSuffix メソッド (String, String, CompareOptions)
指定した CompareOptions 値を使用して、指定した検索対象文字列が、指定したサフィックスで終わるかどうかを判断します。
Overloads Public Overridable Function IsSuffix( _
ByVal source As String, _ ByVal suffix As String, _ ByVal options As CompareOptions _) As Boolean
[C#]
public virtual bool IsSuffix(stringsource,stringsuffix,CompareOptionsoptions);
[C++]
public: virtual bool IsSuffix(String* source,String* suffix,CompareOptionsoptions);
[JScript]
public function IsSuffix(
source : String,suffix : String,options : CompareOptions) : Boolean;
パラメータ
- source
検索範囲とする文字列。 - suffix
source の末尾と比較する文字列。 - options
文字列の比較方法を定義する CompareOptions 値。
戻り値
suffix の長さが source の長さ以下であり、source が suffix で終わる場合は true 。それ以外の場合は false 。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | source が null 参照 (Visual Basic では Nothing) です。
または suffix が null 参照 (Nothing) です。 |
ArgumentException | options が有効な CompareOptions 値ではありません。 |
解説
すべての文字列が空の部分文字列 ("") で開始および終了するため、 suffix が空の文字列の場合、このメソッドは true を返します。
CompareOptions.StringSort 値は、このメソッドに対して有効ではありません。
使用例
[Visual Basic, C#, C++] 次に示すのは、ある文字列が別の文字列のプリフィックスまたはサフィックスになっているかどうかを、 CompareOptions を使用して調べるコード例です。
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
[C#]
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
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
int main() {
// Defines the strings to compare.
String* myStr1 = S"calle";
String* myStr2 = S"llegar";
String* myXfix = S"LLE";
// Uses the CompareInfo property of the InvariantCulture.
CompareInfo* myComp = CultureInfo::InvariantCulture->CompareInfo;
Console::WriteLine(S"IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix);
Console::WriteLine(S" With no CompareOptions : {0}",
__box(myComp->IsSuffix(myStr1, myXfix)));
Console::WriteLine(S" With None : {0}",
__box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::None)));
Console::WriteLine(S" With Ordinal : {0}",
__box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::Ordinal)));
Console::WriteLine(S" With IgnoreCase : {0}",
__box(myComp->IsSuffix(myStr1, myXfix, CompareOptions::IgnoreCase)));
Console::WriteLine(S"IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix);
Console::WriteLine(S" With no CompareOptions : {0}",
__box(myComp->IsPrefix(myStr2, myXfix)));
Console::WriteLine(S" With None : {0}",
__box(myComp->IsPrefix(myStr2, myXfix, CompareOptions::None)));
Console::WriteLine(S" With Ordinal : {0}",
__box(myComp->IsPrefix(myStr2, myXfix, CompareOptions::Ordinal)));
Console::WriteLine(S" With IgnoreCase : {0}",
__box(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
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
CompareInfo クラス | CompareInfo メンバ | System.Globalization 名前空間 | CompareInfo.IsSuffix オーバーロードの一覧 | IsPrefix | CompareOptions