英語で読む

次の方法で共有


CompareInfo.IsSuffix メソッド

定義

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

オーバーロード

IsSuffix(String, String)

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

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

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

IsSuffix(String, String, CompareOptions)

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

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

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

IsSuffix(String, String)

ソース:
CompareInfo.cs
ソース:
CompareInfo.cs
ソース:
CompareInfo.cs

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

C#
public virtual bool IsSuffix (string source, string suffix);
C#
public bool IsSuffix (string source, string suffix);

パラメーター

source
String

検索範囲とする文字列。

suffix
String

source の末尾と比較する文字列。

戻り値

suffix の長さが source の長さ以下であり、sourcesuffix で終わる場合は true、それ以外の場合は false です。

例外

sourcenullです。

または

suffixnullです。

次の例では、文字列が別の文字列のプレフィックスまたはサフィックスであるかどうかを判断します。

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;

      // 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

*/

注釈

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

注意

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

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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

ソース:
CompareInfo.cs
ソース:
CompareInfo.cs
ソース:
CompareInfo.cs

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

C#
public bool IsSuffix (ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);

パラメーター

source
ReadOnlySpan<Char>

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

suffix
ReadOnlySpan<Char>

source の終わりで照合を試行するサフィックス。

options
CompareOptions

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

戻り値

source の終了時に suffix が発生する場合は true。それ以外の場合は false

例外

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

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 5, 6, 7, 8, 9

IsSuffix(String, String, CompareOptions)

ソース:
CompareInfo.cs
ソース:
CompareInfo.cs
ソース:
CompareInfo.cs

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

C#
public virtual bool IsSuffix (string source, string suffix, System.Globalization.CompareOptions options);
C#
public bool IsSuffix (string source, string suffix, System.Globalization.CompareOptions options);

パラメーター

source
String

検索範囲とする文字列。

suffix
String

source の末尾と比較する文字列。

options
CompareOptions

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

戻り値

suffix の長さが source の長さ以下であり、sourcesuffix で終わる場合は true、それ以外の場合は false です。

例外

sourcenullです。

または

suffixnullです。

options に無効な CompareOptions 値が含まれています。

次の例では、 を使用して CompareOptions、文字列が別の文字列のプレフィックスまたはサフィックスであるかどうかを判断します。

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

*/

注釈

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

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

注意

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

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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

ソース:
CompareInfo.cs
ソース:
CompareInfo.cs
ソース:
CompareInfo.cs

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

C#
public bool IsSuffix (ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, System.Globalization.CompareOptions options, out int matchLength);

パラメーター

source
ReadOnlySpan<Char>

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

suffix
ReadOnlySpan<Char>

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

options
CompareOptions

照合中に使用する CompareOptions

matchLength
Int32

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

戻り値

source の終了時に suffix が発生する場合は true。それ以外の場合は false

例外

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

注釈

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

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 5, 6, 7, 8, 9