Share via


TextPointer.GetTextInRun Metoda

Definice

Vrátí text vedle aktuálního TextPointer.

Přetížení

GetTextInRun(LogicalDirection)

Vrátí řetězec obsahující libovolný text sousedící s proudem TextPointer v zadaném logickém směru.

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

Zkopíruje zadaný maximální počet znaků z libovolného sousedního textu v zadaném směru do pole znaků zadaného volajícím.

GetTextInRun(LogicalDirection)

Vrátí řetězec obsahující libovolný text sousedící s proudem TextPointer v zadaném logickém směru.

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

Parametry

direction
LogicalDirection

Jedna z LogicalDirection hodnot, která určuje logický směr, ve kterém se má najít a vrátit libovolný sousední text.

Návraty

Řetězec obsahující libovolný sousední text v zadaném logickém směru nebo Empty pokud nelze najít žádný sousední text.

Příklady

Následující příklad ukazuje použití pro tuto metodu. Příklad používá metodu GetTextInRun k implementaci jednoduchého extraktoru textu. Metoda vrátí řetězcové zřetězení veškerého textu mezi dvěma zadanými TextPointer instancemi.

I když příklad lze použít k extrahování libovolného textu mezi dvěma TextPointer instancemi, je určen pouze pro ilustrativní účely a neměl by se používat v produkčním kódu. Místo toho TextRange.Text použijte vlastnost .

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

Poznámky

Tato metoda vrací pouze nepřerušovaná spuštění textu. Nic se nevrátí, pokud jakýkoli jiný typ symbolu, než Text je sousedící s proudem TextPointer v zadaném směru. Podobně je text vrácen pouze do dalšího netextového symbolu.

Viz také

Platí pro

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

Zkopíruje zadaný maximální počet znaků z libovolného sousedního textu v zadaném směru do pole znaků zadaného volajícím.

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

Parametry

direction
LogicalDirection

Jedna z LogicalDirection hodnot, která určuje logický směr, ve kterém se má najít a zkopírovat libovolný sousední text.

textBuffer
Char[]

Vyrovnávací paměť, do které se zkopíruje libovolný text.

startIndex
Int32

Index, do textBuffer kterého se má začít psát zkopírovaný text.

count
Int32

Maximální počet znaků, které se mají zkopírovat.

Návraty

Počet znaků skutečně zkopírovaných do textBuffer.

Výjimky

startIndex je menší než 0 nebo větší než Length vlastnost textBuffer.

-nebo-

count je menší než 0 nebo větší než zbývající mezera v textBuffer (textBuffer.Length minus startIndex).

Poznámky

Tato metoda vrací pouze nepřerušovaná spuštění textu. Nic se nevrátí, pokud jakýkoli jiný typ symbolu, než Text je sousedící s proudem TextPointer v zadaném směru. Podobně je text vrácen pouze do dalšího netextového symbolu.

Viz také

Platí pro