Partager via


TextPointer.GetTextInRun Méthode

Définition

Retourne le texte adjacent à l’actuel TextPointer.

Surcharges

Nom Description
GetTextInRun(LogicalDirection)

Retourne une chaîne contenant tout texte adjacent au courant TextPointer dans la direction logique spécifiée.

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

Copie le nombre maximal spécifié de caractères de n’importe quel texte adjacent dans la direction spécifiée dans un tableau de caractères fourni par l’appelant.

GetTextInRun(LogicalDirection)

Retourne une chaîne contenant tout texte adjacent au courant TextPointer dans la direction logique spécifiée.

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

Paramètres

direction
LogicalDirection

Une des LogicalDirection valeurs qui spécifie la direction logique dans laquelle rechercher et retourner tout texte adjacent.

Retours

Chaîne contenant un texte adjacent dans la direction logique spécifiée, ou Empty si aucun texte adjacent n’est trouvé.

Exemples

L’exemple suivant illustre une utilisation pour cette méthode. L’exemple utilise la GetTextInRun méthode pour implémenter un extracteur de texte simple. La méthode retourne une concaténation de chaîne de tout le texte entre deux instances spécifiées TextPointer .

Bien que l’exemple puisse être utilisé pour extraire du texte entre deux TextPointer instances, il est destiné uniquement à des fins d’illustration et ne doit pas être utilisé dans le code de production. Utilisez plutôt la propriété 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.

Remarques

Cette méthode retourne uniquement des exécutions ininterrompues de texte. Rien n’est retourné si un type de symbole autre que Text celui qui est adjacent au courant TextPointer dans la direction spécifiée. De même, le texte est retourné uniquement jusqu’au symbole non texte suivant.

Voir aussi

S’applique à

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

Copie le nombre maximal spécifié de caractères de n’importe quel texte adjacent dans la direction spécifiée dans un tableau de caractères fourni par l’appelant.

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

Paramètres

direction
LogicalDirection

Une des LogicalDirection valeurs qui spécifie la direction logique dans laquelle rechercher et copier tout texte adjacent.

textBuffer
Char[]

Mémoire tampon dans laquelle tout texte est copié.

startIndex
Int32

Index dans textBuffer lequel commencer l’écriture de texte copié.

count
Int32

Nombre maximal de caractères à copier.

Retours

Nombre de caractères réellement copiés dans textBuffer.

Exceptions

startIndex est inférieur à 0 ou supérieur à la Length propriété de textBuffer.

- ou -

count est inférieur à 0 ou supérieur à l’espace restant dans textBuffer (textBuffer.Length moins startIndex).

Remarques

Cette méthode retourne uniquement des exécutions ininterrompues de texte. Rien n’est retourné si un type de symbole autre que Text celui qui est adjacent au courant TextPointer dans la direction spécifiée. De même, le texte est retourné uniquement jusqu’au symbole non texte suivant.

Voir aussi

S’applique à