Compartilhar via


TextPointer.GetTextInRun Método

Definição

Retorna o texto adjacente ao atual TextPointer.

Sobrecargas

Nome Description
GetTextInRun(LogicalDirection)

Retorna uma cadeia de caracteres que contém qualquer texto adjacente à atual TextPointer na direção lógica especificada.

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

Copia o número máximo de caracteres especificado de qualquer texto adjacente na direção especificada em uma matriz de caracteres fornecida pelo chamador.

GetTextInRun(LogicalDirection)

Retorna uma cadeia de caracteres que contém qualquer texto adjacente à atual 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 na qual localizar e retornar qualquer texto adjacente.

Retornos

Uma cadeia de caracteres que contém qualquer texto adjacente na direção lógica especificada ou Empty se nenhum texto adjacente puder ser encontrado.

Exemplos

O exemplo a seguir demonstra um uso para esse método. O exemplo usa o GetTextInRun método para implementar um extrator de texto simples. O método retorna uma concatenação de cadeia de caracteres 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, ele destina-se apenas a fins ilustrativos e não deve ser usado no código de produção. Use a propriedade TextRange.Text.

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

Comentários

Esse método retorna apenas execuções ininterruptas de texto. Nada será retornado se qualquer tipo de símbolo que não Text seja adjacente ao atual TextPointer na direção especificada. Da mesma forma, o texto é retornado somente até o próximo símbolo que não é de texto.

Confira também

Aplica-se a

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

Copia o número máximo de caracteres especificado de qualquer texto adjacente na direção especificada em uma matriz de caracteres fornecida 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 na qual localizar e copiar qualquer texto adjacente.

textBuffer
Char[]

Um buffer no qual qualquer texto é copiado.

startIndex
Int32

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

count
Int32

O número máximo de caracteres a serem copiados.

Retornos

O número de caracteres realmente copiados para textBuffer.

Exceções

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

- ou -

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

Comentários

Esse método retorna apenas execuções ininterruptas de texto. Nada será retornado se qualquer tipo de símbolo que não Text seja adjacente ao atual TextPointer na direção especificada. Da mesma forma, o texto é retornado somente até o próximo símbolo que não é de texto.

Confira também

Aplica-se a