TextPointer.GetTextInRun Metoda

Definicja

Zwraca tekst przylegający do bieżącego TextPointerelementu .

Przeciążenia

GetTextInRun(LogicalDirection)

Zwraca ciąg zawierający dowolny tekst przylegający do bieżącego TextPointer w określonym kierunku logicznym.

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

Kopiuje określoną maksymalną liczbę znaków z dowolnego sąsiedniego tekstu w określonym kierunku do tablicy znaków dostarczonej przez obiekt wywołujący.

GetTextInRun(LogicalDirection)

Zwraca ciąg zawierający dowolny tekst przylegający do bieżącego TextPointer w określonym kierunku logicznym.

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

LogicalDirection Jedna z wartości określających kierunek logiczny, w którym ma znajdować i zwracać dowolny sąsiedni tekst.

Zwraca

Ciąg zawierający dowolny sąsiedni tekst w określonym kierunku logicznym lub Empty jeśli nie można odnaleźć sąsiedniego tekstu.

Przykłady

W poniższym przykładzie pokazano użycie tej metody. W przykładzie użyto GetTextInRun metody w celu zaimplementowania prostego wyodrębniania tekstu. Metoda zwraca łączenie ciągu ze wszystkim tekstem między dwoma określonymi TextPointer wystąpieniami.

Chociaż przykład może służyć do wyodrębniania dowolnego tekstu między dwoma TextPointer wystąpieniami, jest przeznaczony tylko do celów ilustracyjnych i nie powinien być używany w kodzie produkcyjnym. TextRange.Text Zamiast tego użyj właściwości .

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

Uwagi

Ta metoda zwraca tylko nieprzerwane przebiegi tekstu. Nic nie jest zwracane, jeśli jakikolwiek typ symbolu inny niż Text sąsiaduje z prądem TextPointer w określonym kierunku. Podobnie tekst jest zwracany tylko do następnego symbolu innego niż tekst.

Zobacz też

Dotyczy

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

Kopiuje określoną maksymalną liczbę znaków z dowolnego sąsiedniego tekstu w określonym kierunku do tablicy znaków dostarczonej przez obiekt wywołujący.

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

LogicalDirection Jedna z wartości określających kierunek logiczny, w którym ma znajdować i kopiować dowolny sąsiedni tekst.

textBuffer
Char[]

Bufor, do którego jest kopiowany dowolny tekst.

startIndex
Int32

Indeks, do textBuffer którego ma rozpocząć pisanie skopiowanego tekstu.

count
Int32

Maksymalna liczba znaków do skopiowania.

Zwraca

Liczba znaków faktycznie skopiowanych do .textBuffer

Wyjątki

startIndex wartość jest mniejsza niż 0 lub większa niż Length właściwość textBuffer.

-lub-

count wartość jest mniejsza niż 0 lub większa niż pozostałe miejsce w textBuffer obiekcie (textBuffer.Length minus startIndex).

Uwagi

Ta metoda zwraca tylko nieprzerwane przebiegi tekstu. Nic nie jest zwracane, jeśli jakikolwiek typ symbolu inny niż Text sąsiaduje z prądem TextPointer w określonym kierunku. Podobnie tekst jest zwracany tylko do następnego symbolu innego niż tekst.

Zobacz też

Dotyczy