CompareInfo.IsPrefix メソッド
文字列が特定のプリフィックスで始まるかどうかを判断します。
オーバーロードの一覧
指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function IsPrefix(String, String) As Boolean
[JScript] public function IsPrefix(String, String) : Boolean;
指定した CompareOptions 値を使用して、指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Function IsPrefix(String, String, CompareOptions) As Boolean
[C#] public virtual bool IsPrefix(string, string, CompareOptions);
[C++] public: virtual bool IsPrefix(String*, String*, CompareOptions);
[JScript] public function IsPrefix(String, String, CompareOptions) : Boolean;
使用例
[Visual Basic, C#, C++] 次に示すのは、ある文字列が別の文字列のプリフィックスまたはサフィックスになっているかどうかを、 CompareOptions を使用して調べるコード例です。
[Visual Basic, C#, C++] メモ ここでは、IsPrefix のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
CompareInfo クラス | CompareInfo メンバ | System.Globalization 名前空間