StringInfo.ParseCombiningCharacters(String) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vrátí indexy každého základního znaku, vysokého náhradního nebo řídicího znaku v zadaném řetězci.
public:
static cli::array <int> ^ ParseCombiningCharacters(System::String ^ str);
public static int[] ParseCombiningCharacters(string str);
static member ParseCombiningCharacters : string -> int[]
Public Shared Function ParseCombiningCharacters (str As String) As Integer()
Parametry
- str
- String
Řetězec, který se má prohledávat.
Návraty
Pole celých čísel obsahujících indexy založené na nule každého základního znaku, vysokého náhradního znaku nebo řídicího znaku v zadaném řetězci.
Výjimky
str je null.
Příklady
Následující příklad ukazuje volání ParseCombiningCharacters metody. Tento příklad kódu je součástí většího příkladu uvedeného pro třídu StringInfo.
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 'ā̈'
// Character at index 3 is 'b'
// Character at index 4 is 'ç'
//
// Result of ParseCombiningCharacters:
// Character 0 starts at index 0
// Character 1 starts at index 3
// Character 2 starts at index 4
Imports System.Text
Imports System.Globalization
Public Module Example
Public Sub Main()
' The string below contains combining characters.
Dim s As String = "a" + ChrW(&h0304) + ChrW(&h0308) + "bc" + ChrW(&h0327)
' Show each 'character' in the string.
EnumTextElements(s)
' Show the index in the string where each 'character' starts.
EnumTextElementIndexes(s)
End Sub
' Show how to enumerate each real character (honoring surrogates) in a string.
Sub EnumTextElements(s As String)
' This StringBuilder holds the output results.
Dim sb As New StringBuilder()
' Use the enumerator returned from GetTextElementEnumerator
' method to examine each real character.
Dim charEnum As TextElementEnumerator = StringInfo.GetTextElementEnumerator(s)
Do While charEnum.MoveNext()
sb.AppendFormat("Character at index {0} is '{1}'{2}",
charEnum.ElementIndex,
charEnum.GetTextElement(),
Environment.NewLine)
Loop
' Show the results.
Console.WriteLine("Result of GetTextElementEnumerator:")
Console.WriteLine(sb)
End Sub
' Show how to discover the index of each real character (honoring surrogates) in a string.
Sub EnumTextElementIndexes(s As String)
' This StringBuilder holds the output results.
Dim sb As New StringBuilder()
' Use the ParseCombiningCharacters method to
' get the index of each real character in the string.
Dim textElemIndex() As Integer = StringInfo.ParseCombiningCharacters(s)
' Iterate through each real character showing the character and the index where it was found.
For i As Int32 = 0 To textElemIndex.Length - 1
sb.AppendFormat("Character {0} starts at index {1}{2}",
i, textElemIndex(i), Environment.NewLine)
Next
' Show the results.
Console.WriteLine("Result of ParseCombiningCharacters:")
Console.WriteLine(sb)
End Sub
End Module
' The example displays the following output:
'
' Result of GetTextElementEnumerator:
' Character at index 0 is 'ā̈'
' Character at index 3 is 'b'
' Character at index 4 is 'ç'
'
' Result of ParseCombiningCharacters:
' Character 0 starts at index 0
' Character 1 starts at index 3
' Character 2 starts at index 4
Poznámky
Standard Unicode definuje náhradní dvojici jako kódovanou znakovou reprezentaci pro jeden abstraktní znak, který se skládá ze sekvence dvou jednotek kódu, kde první jednotka páru je vysoká náhrada a druhá je nízká náhrada. Vysoká náhrada je bod kódu Unicode v rozsahu U+D800 až U+DBFF a nízká náhrada je bod kódu Unicode v rozsahu U+DC00 až U+DFFF.
Řídicí znak je znak, pro který je hodnota Unicode U+007F nebo v rozsahu U+0000 až U+001F nebo U+0080 až U+009F.
.NET definuje textový prvek jako jednotku textu, která se zobrazí jako jeden znak, tj. grafeme. Textový prvek může být základní znak, náhradní dvojice nebo kombinace sekvence znaků. Standard Unicode definuje kombinování sekvence znaků jako kombinaci základního znaku a jednoho nebo více kombinujících znaků. Náhradní dvojice může představovat základní znak nebo kombinační znak.
Pokud je kombinace znakové sekvence neplatná, vrátí se také každý zkombinující znak v této sekvenci.
Každý index ve výsledném poli je začátek textového prvku, tj. index základního znaku nebo vysokého náhradního znaku.
Délka každého prvku se snadno vypočítá jako rozdíl mezi po sobě jdoucími indexy. Délka pole bude vždy menší nebo rovna délce řetězce. Například vzhledem k řetězci "\u4f00\u302a\ud800\udc00\u4f01", tato metoda vrátí indexy 0, 2 a 4.
Ekvivalentní členové
Od verze 2.0 rozhraní .NET Framework SubstringByTextElements poskytuje metoda a LengthInTextElements vlastnost snadno použitelnou implementaci funkcí nabízených metodou ParseCombiningCharacters .