Compartir por


TextPointer.GetTextInRun Método

Definición

Devuelve texto adyacente al objeto actual TextPointer.

Sobrecargas

Nombre Description
GetTextInRun(LogicalDirection)

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

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

Copia el número máximo de caracteres especificado de cualquier texto adyacente en la dirección especificada en una matriz de caracteres proporcionado por el autor de la llamada.

GetTextInRun(LogicalDirection)

Devuelve una cadena que contiene cualquier texto adyacente al actual TextPointer 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 LogicalDirection valores que especifica la dirección lógica en la que buscar y devolver cualquier texto adyacente.

Devoluciones

Cadena que contiene cualquier texto adyacente en la dirección lógica especificada o Empty si no se encuentra 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 algún 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 máximo de caracteres especificado de cualquier texto adyacente en la dirección especificada en una matriz de caracteres proporcionado por el autor de la llamada.

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 LogicalDirection valores que especifica la dirección lógica en la que buscar y copiar cualquier texto adyacente.

textBuffer
Char[]

Búfer en el que se copia cualquier texto.

startIndex
Int32

Índice en el textBuffer que empezar a escribir texto copiado.

count
Int32

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

Devoluciones

Número de caracteres copiados realmente en textBuffer.

Excepciones

startIndex es menor que 0 o mayor que la Length propiedad 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 algún 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