TextPointer.GetTextInRun Método

Definição

Devolve texto adjacente ao atual TextPointer.

Sobrecargas

Name Description
GetTextInRun(LogicalDirection)

Devolve uma cadeia contendo qualquer texto adjacente à corrente TextPointer na direção lógica especificada.

GetTextInRun(LogicalDirection, Char[], Int32, Int32)

Copia o número máximo especificado de caracteres de qualquer texto adjacente na direção especificada para um array de caracteres fornecido pelo chamador.

GetTextInRun(LogicalDirection)

Devolve uma cadeia contendo qualquer texto adjacente à corrente TextPointer na direção lógica especificada.

public:
 System::String ^ GetTextInRun(System::Windows::Documents::LogicalDirection direction);
public string GetTextInRun(System.Windows.Documents.LogicalDirection direction);
member this.GetTextInRun : System.Windows.Documents.LogicalDirection -> string
Public Function GetTextInRun (direction As LogicalDirection) As String

Parâmetros

direction
LogicalDirection

Um dos LogicalDirection valores que especifica a direção lógica para encontrar e devolver qualquer texto adjacente.

Devoluções

Uma cadeia contendo qualquer texto adjacente na direção lógica especificada, ou Empty se não for possível encontrar texto adjacente.

Exemplos

O exemplo seguinte demonstra a utilização deste método. O exemplo utiliza o GetTextInRun método para implementar um extrator de texto simples. O método devolve uma concatenação de strings de todo o texto entre duas instâncias especificadas TextPointer .

Embora o exemplo possa ser usado para extrair qualquer texto entre duas TextPointer instâncias, destina-se apenas a fins ilustrativos e não deve ser usado em código de produção. Utilize a propriedade TextRange.Text em vez disso.

// Returns a string containing the text content between two specified TextPointers.
string GetTextBetweenTextPointers(TextPointer start, TextPointer end)
{
    StringBuilder buffer = new StringBuilder();
 
    while (start != null && start.CompareTo(end) < 0)
    {
        if (start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
            buffer.Append(start.GetTextInRun(LogicalDirection.Forward));
 
        // Note that when the TextPointer points into a text run, this skips over the entire
        // run, not just the current character in the run.
        start = start.GetNextContextPosition(LogicalDirection.Forward);
    }
    return buffer.ToString();
} // End GetTextBetweenPointers.
' Returns a string containing the text content between two specified TextPointers.
Private Function GetTextBetweenTextPointers(ByVal start As TextPointer, ByVal [end] As TextPointer) As String
    Dim buffer As New StringBuilder()

    Do While start IsNot Nothing AndAlso start.CompareTo([end]) < 0
        If start.GetPointerContext(LogicalDirection.Forward) = TextPointerContext.Text Then
            buffer.Append(start.GetTextInRun(LogicalDirection.Forward))
        End If

        ' Note that when the TextPointer points into a text run, this skips over the entire
        ' run, not just the current character in the run.
        start = start.GetNextContextPosition(LogicalDirection.Forward)
    Loop
    Return buffer.ToString()

End Function ' End GetTextBetweenPointers.

Observações

Este método devolve apenas sequências ininterruptas de texto. Nada é devolvido se qualquer tipo de símbolo diferente Text de estiver adjacente à corrente TextPointer na direção especificada. De forma semelhante, o texto é devolvido apenas até ao símbolo não textual seguinte.

Ver também

Aplica-se a

GetTextInRun(LogicalDirection, Char[], Int32, Int32)

Copia o número máximo especificado de caracteres de qualquer texto adjacente na direção especificada para um array de caracteres fornecido pelo chamador.

public:
 int GetTextInRun(System::Windows::Documents::LogicalDirection direction, cli::array <char> ^ textBuffer, int startIndex, int count);
public int GetTextInRun(System.Windows.Documents.LogicalDirection direction, char[] textBuffer, int startIndex, int count);
member this.GetTextInRun : System.Windows.Documents.LogicalDirection * char[] * int * int -> int
Public Function GetTextInRun (direction As LogicalDirection, textBuffer As Char(), startIndex As Integer, count As Integer) As Integer

Parâmetros

direction
LogicalDirection

Um dos LogicalDirection valores que especifica a direção lógica para encontrar e copiar qualquer texto adjacente.

textBuffer
Char[]

Um buffer para onde qualquer texto é copiado.

startIndex
Int32

Um índice para textBuffer começar a escrever texto copiado.

count
Int32

O número máximo de caracteres a copiar.

Devoluções

O número de caracteres realmente copiados para textBuffer.

Exceções

startIndex é inferior a 0 ou maior que a Length propriedade de textBuffer.

-ou-

count é menor que 0 ou maior do que o espaço restante em textBuffer (textBuffer.Length menos startIndex).

Observações

Este método devolve apenas sequências ininterruptas de texto. Nada é devolvido se qualquer tipo de símbolo diferente Text de estiver adjacente à corrente TextPointer na direção especificada. De forma semelhante, o texto é devolvido apenas até ao símbolo não textual seguinte.

Ver também

Aplica-se a