TextPointer.GetTextInRun Metod

Definition

Returnerar text intill den aktuella TextPointer.

Överlagringar

Name Description
GetTextInRun(LogicalDirection)

Returnerar en sträng som innehåller text intill den aktuella TextPointer i den angivna logiska riktningen.

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

Kopierar det angivna maximala antalet tecken från valfri intilliggande text i den angivna riktningen till en teckenmatris som tillhandahålls av anroparen.

GetTextInRun(LogicalDirection)

Returnerar en sträng som innehåller text intill den aktuella TextPointer i den angivna logiska riktningen.

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

Parametrar

direction
LogicalDirection

Ett av de LogicalDirection värden som anger den logiska riktning där du kan hitta och returnera eventuell intilliggande text.

Returer

En sträng som innehåller eventuell intilliggande text i den angivna logiska riktningen eller Empty om det inte går att hitta någon intilliggande text.

Exempel

I följande exempel visas en användning för den här metoden. I exemplet används GetTextInRun metoden för att implementera en enkel textextraktor. Metoden returnerar en strängsammanfogning av all text mellan två angivna TextPointer instanser.

Exemplet kan användas för att extrahera text mellan två TextPointer instanser, men det är endast avsett för illustrativa ändamål och bör inte användas i produktionskod. Använd egenskapen TextRange.Text i stället.

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

Kommentarer

Den här metoden returnerar endast oavbrutna körningar av text. Ingenting returneras om någon annan symboltyp än Text är intill strömmen TextPointer i den angivna riktningen. På samma sätt returneras endast text upp till nästa icke-textsymbol.

Se även

Gäller för

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

Kopierar det angivna maximala antalet tecken från valfri intilliggande text i den angivna riktningen till en teckenmatris som tillhandahålls av anroparen.

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

Parametrar

direction
LogicalDirection

Ett av de LogicalDirection värden som anger den logiska riktning där du kan hitta och kopiera eventuell intilliggande text.

textBuffer
Char[]

En buffert som all text kopieras till.

startIndex
Int32

Ett index textBuffer där du kan börja skriva kopierad text.

count
Int32

Det maximala antalet tecken som ska kopieras.

Returer

Antalet tecken som faktiskt kopieras till textBuffer.

Undantag

startIndex är mindre än 0 eller större än Length egenskapen textBufferför .

-eller-

count är mindre än 0 eller större än det återstående utrymmet i textBuffer (textBuffer.Length minus startIndex).

Kommentarer

Den här metoden returnerar endast oavbrutna körningar av text. Ingenting returneras om någon annan symboltyp än Text är intill strömmen TextPointer i den angivna riktningen. På samma sätt returneras endast text upp till nästa icke-textsymbol.

Se även

Gäller för