TextPointer.GetTextInRun Método

Definición

Devuelve el texto adyacente al TextPointer actual.

Sobrecargas

GetTextInRun(LogicalDirection)

Devuelve una cadena que contiene cualquier texto adyacente al TextPointer actual en la dirección lógica especificada.

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

Copia el número de caracteres máximo especificado desde cualquier texto adyacente en la dirección especificada en una matriz de caracteres proporcionada por un llamador.

GetTextInRun(LogicalDirection)

Devuelve una cadena que contiene cualquier texto adyacente al TextPointer actual en la dirección 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

Uno de los valores de LogicalDirection que especifica la dirección lógica en la que buscar y devolver cualquier texto adyacente.

Devoluciones

Una cadena que contiene cualquier texto adyacente en la dirección lógica especificada o Empty si no se puede buscar ningún texto adyacente.

Ejemplos

En el ejemplo siguiente se muestra un uso para este método. En el ejemplo se usa el GetTextInRun método para implementar un extractor de texto simple. El método devuelve una concatenación de cadena de todo el texto entre dos instancias especificadas TextPointer .

Aunque el ejemplo se puede usar para extraer cualquier texto entre dos TextPointer instancias, está pensado solo para fines ilustrativos y no debe usarse en el código de producción. Utilice la propiedad TextRange.Text en su lugar.

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

Comentarios

Este método devuelve solo ejecuciones ininterrumpidas de texto. No se devuelve nada si cualquier tipo de símbolo distinto Text de es adyacente al actual TextPointer en la dirección especificada. Del mismo modo, el texto solo se devuelve hasta el siguiente símbolo que no es de texto.

Consulte también

Se aplica a

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

Copia el número de caracteres máximo especificado desde cualquier texto adyacente en la dirección especificada en una matriz de caracteres proporcionada por un llamador.

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

Uno de los valores de LogicalDirection que especifica la dirección lógica en la que buscar y copiar cualquier texto adyacente.

textBuffer
Char[]

Un búfer en el que se copia texto.

startIndex
Int32

Un índice en textBuffer en el que se comienza a escribir texto copiado.

count
Int32

Número máximo de caracteres que se pueden copiar.

Devoluciones

Número de caracteres copiados realmente en textBuffer.

Excepciones

startIndex es menor que 0 o mayor que la propiedad Length de textBuffer.

o bien

count es menor que 0 o mayor que el espacio restante en textBuffer (textBuffer.Length menos startIndex).

Comentarios

Este método devuelve solo ejecuciones ininterrumpidas de texto. No se devuelve nada si cualquier tipo de símbolo distinto Text de es adyacente al actual TextPointer en la dirección especificada. Del mismo modo, el texto solo se devuelve hasta el siguiente símbolo que no es de texto.

Consulte también

Se aplica a