CompareInfo.IsPrefix メソッド

定義

文字列が特定のプレフィックスで始まるかどうかを判断します。

オーバーロード

IsPrefix(String, String)

指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。

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

読み取り専用文字スパンが特定のプレフィックスから始まるかどうかを決定します。

IsPrefix(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した検索対象文字列が指定したプレフィックスで始まるかどうかを判断します。

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

文字列が特定のプレフィックスで始まるかどうかを判断します。

IsPrefix(String, String)

指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。

public:
 virtual bool IsPrefix(System::String ^ source, System::String ^ prefix);
public:
 bool IsPrefix(System::String ^ source, System::String ^ prefix);
public virtual bool IsPrefix (string source, string prefix);
public bool IsPrefix (string source, string prefix);
abstract member IsPrefix : string * string -> bool
override this.IsPrefix : string * string -> bool
member this.IsPrefix : string * string -> bool
Public Overridable Function IsPrefix (source As String, prefix As String) As Boolean
Public Function IsPrefix (source As String, prefix As String) As Boolean

パラメーター

source
String

検索範囲とする文字列。

prefix
String

source の先頭と比較する文字列。

戻り値

Boolean

prefix の長さが source の長さ以下で、sourceprefix で始まる場合は true、それ以外の場合は false です。

例外

sourcenullです。

または

prefixnullです。

次の例では、文字列が別の文字列のプレフィックスかサフィックスかを決定します。

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

注釈

すべての文字列は、空の部分文字列 ("") で開始および終了します。したがって、空の文字列の場合prefix、このメソッドは .true

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

こちらもご覧ください

適用対象

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

読み取り専用文字スパンが特定のプレフィックスから始まるかどうかを決定します。

public bool IsPrefix (ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), Optional options As CompareOptions = System.Globalization.CompareOptions.None) As Boolean

パラメーター

source
ReadOnlySpan<Char>

中で検索する読み取り専用文字スパン。

prefix
ReadOnlySpan<Char>

source の始めで照合を試行するプレフィックス。

options
CompareOptions

照合中に使用する CompareOptions 列挙値の任意の組み合わせ。 既定値は None です。

戻り値

Boolean

source の開始時に prefix が発生する場合は true。それ以外の場合は false

例外

options には、サポートされていない組み合わせのフラグが含まれています。

適用対象

IsPrefix(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した検索対象文字列が指定したプレフィックスで始まるかどうかを判断します。

public:
 virtual bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public:
 bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public virtual bool IsPrefix (string source, string prefix, System.Globalization.CompareOptions options);
public bool IsPrefix (string source, string prefix, System.Globalization.CompareOptions options);
abstract member IsPrefix : string * string * System.Globalization.CompareOptions -> bool
override this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
member this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
Public Overridable Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean
Public Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean

パラメーター

source
String

検索範囲とする文字列。

prefix
String

source の先頭と比較する文字列。

options
CompareOptions

sourceprefix の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Boolean

prefix の長さが source の長さ以下で、sourceprefix で始まる場合は true、それ以外の場合は false です。

例外

sourcenullです。

または

prefixnullです。

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

注釈

すべての文字列は、空の部分文字列 ("") で始まり、終わります。したがって、空の文字列の場合 prefix 、このメソッド trueは .

このメソッドの CompareOptions.StringSort 値は無効です。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

こちらもご覧ください

適用対象

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

文字列が特定のプレフィックスで始まるかどうかを判断します。

public:
 bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System::Globalization::CompareOptions options, [Runtime::InteropServices::Out] int % matchLength);
public bool IsPrefix (ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options, out int matchLength);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions * int -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), options As CompareOptions, ByRef matchLength As Integer) As Boolean

パラメーター

source
ReadOnlySpan<Char>

中で検索する読み取り専用文字スパン。

prefix
ReadOnlySpan<Char>

source の始めで照合を試行するプレフィックスを含む文字の読み取り専用スパン。

options
CompareOptions

照合中に使用する CompareOptions

matchLength
Int32

このメソッドから制御が戻るときに、目的のプレフィックスに一致した source の文字数が格納されます。 言語的な比較が実行された場合は、prefix の長さとは異なることがあります。 プレフィックスが一致しなかった場合は 0 に設定されます。

戻り値

Boolean

source の開始時に prefix が発生する場合は true。それ以外の場合は false

例外

options には、サポートされていない組み合わせのフラグが含まれています。

注釈

このメソッドは、引数を受け取matchLengthらない他IsPrefix(String, String, CompareOptions)のオーバーロードよりもオーバーヘッドが大きくなります。 このオーバーロードは、一致する長さの情報が必要な場合にのみ呼び出します。

適用対象