StringInfo クラス
アセンブリ: mscorlib (mscorlib.dll 内)


.NET Framework は、単一の文字として表示されるテキストの単位、つまり書記素としてテキスト要素を定義します。テキスト要素は、基本文字、サロゲート ペア、または組み合わせた文字シーケンスの場合があります。Unicode Standard は、サロゲート ペアを 2 つのコード単位から成る単一の抽象文字を表すコード化文字表現として定義します。ペアの最初の単位が上位サロゲート、2 番目の単位が下位サロゲートとなります。Unicode Standard は、組み合わせ文字シーケンスを 1 つの基本文字と 1 つ以上の組み合わせ文字の組み合わせとして定義します。サロゲート ペアは、基本文字または組み合わせた文字を表すことができます。
サロゲート ペアおよび組み合わせ文字シーケンスの詳細については、http://www.unicode.org の「The Unicode Standard」を参照してください。

この例は、StringInfo クラスの GetTextElementEnumerator メソッドおよび ParseCombiningCharacters メソッドを使用して、サロゲートおよび組み合わせ文字を含む文字列を操作する方法を示します。
using System; using System.Text; using System.Globalization; public sealed class App { static void Main() { // The string below contains combining characters. String s = "a\u0304\u0308bc\u0327"; // Show each 'character' in the string. EnumTextElements(s); // Show the index in the string where each 'character' starts. EnumTextElementIndexes(s); } // Show how to enumerate each real character (honoring surrogates) in a string. static void EnumTextElements(String s) { // This StringBuilder holds the output results. StringBuilder sb = new StringBuilder(); // Use the enumerator returned from GetTextElementEnumerator // method to examine each real character. TextElementEnumerator charEnum = StringInfo.GetTextElementEnumerator(s); while (charEnum.MoveNext()) { sb.AppendFormat( "Character at index {0} is '{1}'{2}", charEnum.ElementIndex, charEnum.GetTextElement(), Environment.NewLine); } // Show the results. Console.WriteLine("Result of GetTextElementEnumerator:"); Console.WriteLine(sb); } // Show how to discover the index of each real character (honoring surrogates) in a string. static void EnumTextElementIndexes(String s) { // This StringBuilder holds the output results. StringBuilder sb = new StringBuilder(); // Use the ParseCombiningCharacters method to // get the index of each real character in the string. Int32[] textElemIndex = StringInfo.ParseCombiningCharacters(s); // Iterate through each real character showing the character and the index where it was found. for (Int32 i = 0; i < textElemIndex.Length; i++) { sb.AppendFormat( "Character {0} starts at index {1}{2}", i, textElemIndex[i], Environment.NewLine); } // Show the results. Console.WriteLine("Result of ParseCombiningCharacters:"); Console.WriteLine(sb); } } // This code produces the following output. // // Result of GetTextElementEnumerator: // Character at index 0 is 'a-"' // Character at index 3 is 'b' // Character at index 4 is 'c,' // // Result of ParseCombiningCharacters: // Character 0 starts at index 0 // Character 1 starts at index 3 // Character 2 starts at index 4
using namespace System; using namespace System::Text; using namespace System::Globalization; // Show how to enumerate each real character (honoring surrogates) // in a string. void EnumTextElements(String^ combiningChars) { // This StringBuilder holds the output results. StringBuilder^ sb = gcnew StringBuilder(); // Use the enumerator returned from GetTextElementEnumerator // method to examine each real character. TextElementEnumerator^ charEnum = StringInfo::GetTextElementEnumerator(combiningChars); while (charEnum->MoveNext()) { sb->AppendFormat("Character at index {0} is '{1}'{2}", charEnum->ElementIndex, charEnum->GetTextElement(), Environment::NewLine); } // Show the results. Console::WriteLine("Result of GetTextElementEnumerator:"); Console::WriteLine(sb); } // Show how to discover the index of each real character // (honoring surrogates) in a string. void EnumTextElementIndexes(String^ combiningChars) { // This StringBuilder holds the output results. StringBuilder^ sb = gcnew StringBuilder(); // Use the ParseCombiningCharacters method to // get the index of each real character in the string. array <int>^ textElemIndex = StringInfo::ParseCombiningCharacters(combiningChars); // Iterate through each real character showing the character // and the index where it was found. for (int i = 0; i < textElemIndex->Length; i++) { sb->AppendFormat("Character {0} starts at index {1}{2}", i, textElemIndex[i], Environment::NewLine); } // Show the results. Console::WriteLine("Result of ParseCombiningCharacters:"); Console::WriteLine(sb); } int main() { // The string below contains combining characters. String^ combiningChars = L"a\u0304\u0308bc\u0327"; // Show each 'character' in the string. EnumTextElements(combiningChars); // Show the index in the string where each 'character' starts. EnumTextElementIndexes(combiningChars); }; // This code produces the following output. // // Result of GetTextElementEnumerator: // Character at index 0 is 'a-"' // Character at index 3 is 'b' // Character at index 4 is 'c,' // // Result of ParseCombiningCharacters: // Character 0 starts at index 0 // Character 1 starts at index 3 // Character 2 starts at index 4

System.Globalization.StringInfo


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


StringInfo コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


StringInfo コンストラクタ (String)
アセンブリ: mscorlib (mscorlib.dll 内)



Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


StringInfo コンストラクタ

名前 | 説明 |
---|---|
StringInfo () | StringInfo クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
StringInfo (String) | StringInfo クラスの新しいインスタンスを指定された文字列に初期化します。 .NET Compact Framework によってサポートされています。 |

StringInfo プロパティ
StringInfo メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 オーバーライドされます。 |
![]() | GetHashCode | オーバーライドされます。 現在の StringInfo オブジェクトの値のハッシュ コードを計算します。 |
![]() | GetNextTextElement | オーバーロードされます。 指定した文字列の最初のテキスト要素を取得します。 |
![]() | GetTextElementEnumerator | オーバーロードされます。 文字列のテキスト要素を反復処理する列挙子を返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ParseCombiningCharacters | 指定した文字列の各基本文字、上位サロゲート、または制御文字のインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | SubstringByTextElements | オーバーロードされます。 現在の StringInfo オブジェクトの値からテキスト要素の部分文字列を取得します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

StringInfo メンバ
文字列をテキスト要素に分割し、そのテキスト要素を反復処理する機能を提供します。
StringInfo データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 オーバーライドされます。 |
![]() | GetHashCode | オーバーライドされます。 現在の StringInfo オブジェクトの値のハッシュ コードを計算します。 |
![]() | GetNextTextElement | オーバーロードされます。 指定した文字列の最初のテキスト要素を取得します。 |
![]() | GetTextElementEnumerator | オーバーロードされます。 文字列のテキスト要素を反復処理する列挙子を返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ParseCombiningCharacters | 指定した文字列の各基本文字、上位サロゲート、または制御文字のインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | SubstringByTextElements | オーバーロードされます。 現在の StringInfo オブジェクトの値からテキスト要素の部分文字列を取得します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- StringInfoのページへのリンク