Condividi tramite


TextPointer.GetTextInRun Metodo

Definizione

Restituisce il testo adiacente all'oggetto corrente TextPointer.

Overload

Nome Descrizione
GetTextInRun(LogicalDirection)

Restituisce una stringa contenente qualsiasi testo adiacente all'oggetto corrente TextPointer nella direzione logica specificata.

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

Copia il numero massimo di caratteri specificato da qualsiasi testo adiacente nella direzione specificata in una matrice di caratteri fornita dal chiamante.

GetTextInRun(LogicalDirection)

Restituisce una stringa contenente qualsiasi testo adiacente all'oggetto corrente TextPointer nella direzione logica specificata.

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

Parametri

direction
LogicalDirection

Uno dei LogicalDirection valori che specifica la direzione logica in cui trovare e restituire qualsiasi testo adiacente.

Restituisce

Stringa contenente qualsiasi testo adiacente nella direzione logica specificata o Empty se non è possibile trovare testo adiacente.

Esempio

Nell'esempio seguente viene illustrato un utilizzo per questo metodo. Nell'esempio viene utilizzato il GetTextInRun metodo per implementare un estrattore di testo semplice. Il metodo restituisce una concatenazione di stringa di tutto il testo tra due istanze specificate TextPointer .

Anche se l'esempio può essere usato per estrarre testo tra due TextPointer istanze, è destinato solo a scopi illustrativi e non deve essere usato nel codice di produzione. Utilizzare in alternativa la proprietà 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.

Commenti

Questo metodo restituisce solo esecuzioni di testo senza interruzioni. Non viene restituito alcun valore se un tipo di simbolo diverso da Text è adiacente all'oggetto corrente TextPointer nella direzione specificata. Analogamente, il testo viene restituito solo fino al simbolo non di testo successivo.

Vedi anche

Si applica a

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

Copia il numero massimo di caratteri specificato da qualsiasi testo adiacente nella direzione specificata in una matrice di caratteri fornita dal chiamante.

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

Parametri

direction
LogicalDirection

Uno dei LogicalDirection valori che specifica la direzione logica in cui trovare e copiare qualsiasi testo adiacente.

textBuffer
Char[]

Buffer in cui viene copiato qualsiasi testo.

startIndex
Int32

Indice in in textBuffer cui iniziare a scrivere testo copiato.

count
Int32

Numero massimo di caratteri da copiare.

Restituisce

Numero di caratteri effettivamente copiati in textBuffer.

Eccezioni

startIndex è minore di 0 o maggiore della Length proprietà di textBuffer.

oppure

count è minore di 0 o maggiore dello spazio rimanente in textBuffer (textBuffer.Length meno startIndex).

Commenti

Questo metodo restituisce solo esecuzioni di testo senza interruzioni. Non viene restituito alcun valore se un tipo di simbolo diverso da Text è adiacente all'oggetto corrente TextPointer nella direzione specificata. Analogamente, il testo viene restituito solo fino al simbolo non di testo successivo.

Vedi anche

Si applica a