StringInfo.ParseCombiningCharacters(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve os índices de cada carácter base, substituto alto ou carácter de controlo dentro da cadeia especificada.
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()
Parâmetros
- str
- String
A cadeia de caracteres a ser pesquisada.
Devoluções
Um array de inteiros que contém os índices baseados em zero de cada carácter base, substituto alto ou carácter de controlo dentro da cadeia especificada.
Exceções
str é null.
Exemplos
O exemplo seguinte demonstra chamar o ParseCombiningCharacters método. Este exemplo de código faz parte de um exemplo maior fornecido para a StringInfo classe.
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
Observações
A Norma Unicode define um par substituto como uma representação codificada de caracteres para um único carácter abstrato que consiste numa sequência de duas unidades de código, onde a primeira unidade do par é um substituto alto e a segunda é um substituto baixo. Um substituto alto é um ponto de código Unicode no intervalo U+D800 a U+DBFF e um substituto baixo é um ponto de código Unicode no intervalo U+DC00 a U+DFFF.
Um carácter de controlo é um carácter cujo valor Unicode é U+007F ou está no intervalo de U+0000 a U+001F ou de U+0080 a U+009F.
.NET define um elemento de texto como uma unidade de texto que é apresentada como um único carácter, ou seja, um grafema. Um elemento de texto pode ser um carácter base, um par substituto ou uma sequência combinativa de caracteres. O Padrão Unicode define uma sequência de caracteres combinados como uma combinação de um carácter base e um ou mais caracteres combinados. Um par substituto pode representar um carácter base ou um carácter combinado.
Se uma sequência de caracteres combinados for inválida, todos os caracteres combinadores dessa sequência também são devolvidos.
Cada índice no array resultante é o início de um elemento de texto, ou seja, o índice do carácter base ou do substituto alto.
O comprimento de cada elemento é facilmente calculado como a diferença entre índices sucessivos. O comprimento da matriz será sempre menor ou igual ao comprimento da corda. Por exemplo, dada a cadeia "\u4f00\u302a\ud800\udc00\u4f01", este método devolve os índices 0, 2 e 4.
Membros Equivalentes
A partir da versão 2.0 do .NET Framework, o método SubstringByTextElements e a propriedade LengthInTextElements fornecem uma implementação fácil de usar da funcionalidade oferecida pelo método ParseCombiningCharacters.