CompareInfo.IsPrefix CompareInfo.IsPrefix CompareInfo.IsPrefix CompareInfo.IsPrefix Method

定義

文字列が特定のプレフィックスで始まるかどうかを判断します。Determines whether a string starts with a specific prefix.

オーバーロード

IsPrefix(String, String) IsPrefix(String, String) IsPrefix(String, String) IsPrefix(String, String)

指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。Determines whether the specified source string starts with the specified prefix.

IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した検索対象文字列が指定したプレフィックスで始まるかどうかを判断します。Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value.

IsPrefix(String, String) IsPrefix(String, String) IsPrefix(String, String) IsPrefix(String, String)

指定した検索対象文字列が指定したプリフィックスで始まるかどうかを判断します。Determines whether the specified source string starts with the specified prefix.

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

パラメーター

source
String String String String

検索範囲とする文字列。The string to search in.

prefix
String String String String

source の先頭と比較する文字列。The string to compare with the beginning of source.

戻り値

prefix の長さが source の長さ以下で、sourceprefix で始まる場合は true、それ以外の場合は false です。true if the length of prefix is less than or equal to the length of source and source starts with prefix; otherwise, false.

例外

sourcenullです。source is null.

- または --or- prefixnullです。prefix is null.

次の例は、文字列が、プレフィックスまたはサフィックスを別の文字列かどうかを判断します。The following example determines whether a string is the prefix or suffix of another string.

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
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 'Main 

End Class 'SamplesCompareInfo


'This code produces the following output.
'
'IsPrefix( calle, lle ) : False
'IsPrefix( llegar, lle ) : True
'IsSuffix( calle, lle ) : True
'IsSuffix( llegar, lle ) : False

注釈

すべての文字列が開始し、空の部分文字列で終了 ("");そのため場合、prefix空の文字列は、このメソッドが返されるtrueします。Every string starts and ends with an empty substring (""); therefore, if prefix is an empty string, this method returns true.

注意

可能であれば、メソッドを呼び出し、文字列比較を型のパラメーターを持つCompareOptions予想比較の種類を指定します。When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. 一般的な規則としてユーザー インターフェイスに表示される文字列を比較するため (現在のカルチャを使用して) 言語のオプションを使用し、指定CompareOptions.OrdinalまたはCompareOptions.OrdinalIgnoreCaseセキュリティ比較します。As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

こちらもご覧ください

IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions) IsPrefix(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した検索対象文字列が指定したプレフィックスで始まるかどうかを判断します。Determines whether the specified source string starts with the specified prefix using the specified CompareOptions value.

public:
 virtual bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public virtual 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
Public Overridable Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean

パラメーター

source
String String String String

検索範囲とする文字列。The string to search in.

prefix
String String String String

source の先頭と比較する文字列。The string to compare with the beginning of source.

options
CompareOptions CompareOptions CompareOptions CompareOptions

sourceprefix の比較方法を定義する値。A value that defines how source and prefix should be compared. options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。options is either the enumeration value Ordinal, or a bitwise combination of one or more of the following values: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth, and IgnoreKanaType.

戻り値

prefix の長さが source の長さ以下で、sourceprefix で始まる場合は true、それ以外の場合は false です。true if the length of prefix is less than or equal to the length of source and source starts with prefix; otherwise, false.

例外

sourcenullです。source is null.

- または --or- prefixnullです。prefix is null.

options に無効な CompareOptions 値が含まれています。options contains an invalid CompareOptions value.

次の例は、文字列は、プレフィックスまたはサフィックスを別の文字列を使用するかどうかを判断CompareOptionsします。The following example determines whether a string is the prefix or suffix of another string using 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
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

注釈

すべての文字列が開始し、空の部分文字列で終了 ("");そのため場合、prefix空の文字列は、このメソッドが返されるtrueします。Every string starts and ends with an empty substring (""); therefore, if prefix is an empty string, this method returns true.

CompareOptions.StringSort値がこのメソッドは無効です。The CompareOptions.StringSort value is not valid for this method.

注意

可能であれば、メソッドを呼び出し、文字列比較を型のパラメーターを持つCompareOptions予想比較の種類を指定します。When possible, you should call string comparison methods that have a parameter of type CompareOptions to specify the kind of comparison expected. 一般的な規則としてユーザー インターフェイスに表示される文字列を比較するため (現在のカルチャを使用して) 言語のオプションを使用し、指定CompareOptions.OrdinalまたはCompareOptions.OrdinalIgnoreCaseセキュリティ比較します。As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.

こちらもご覧ください

適用対象