Share via


TextPointer.GetTextInRun メソッド

定義

現在の TextPointer に隣接するテキストを返します。

オーバーロード

GetTextInRun(LogicalDirection)

指定された論理方向で現在の TextPointer に隣接するテキストを格納する文字列を返します。

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

指定された方向の隣接するテキストから、指定された最大数の文字を、呼び出し元が用意した文字配列にコピーします。

GetTextInRun(LogicalDirection)

指定された論理方向で現在の TextPointer に隣接するテキストを格納する文字列を返します。

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

パラメーター

direction
LogicalDirection

隣接するテキストを検索して返す論理方向を指定する LogicalDirection 値のいずれか。

戻り値

指定された論理方向の隣接するテキストを格納する文字列。隣接するテキストが見つからない場合は Empty

次の例では、このメソッドの使用方法を示します。 この例では、 メソッドを GetTextInRun 使用して単純なテキスト抽出器を実装します。 メソッドは、指定された TextPointer 2 つのインスタンス間のすべてのテキストの文字列連結を返します。

この例は 2 つの TextPointer インスタンス間の任意のテキストを抽出するために使用できますが、例示のみを目的としており、実稼働コードでは使用しないでください。 代わりに、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.

注釈

このメソッドは、中断されないテキストの実行のみを返します。 以外 Text のシンボル型が、指定した方向の現在 TextPointer の に隣接している場合は、何も返されません。 同様に、テキストは次の非テキストシンボルまでしか返されません。

こちらもご覧ください

適用対象

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

指定された方向の隣接するテキストから、指定された最大数の文字を、呼び出し元が用意した文字配列にコピーします。

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

パラメーター

direction
LogicalDirection

隣接するテキストを検索してコピーする論理方向を指定する LogicalDirection 値のいずれか。

textBuffer
Char[]

テキストのコピー先のバッファー。

startIndex
Int32

コピーしたテキストの書き込みを開始する textBuffer のインデックス。

count
Int32

コピーする文字の最大数。

戻り値

実際に textBuffer にコピーされた文字数。

例外

startIndex が 0 より小さいか、textBufferLength プロパティより大きい。

- または -

count が 0 より小さいか、 の残りの領域 textBuffer より大きい (textBuffer.Length から を引いた startIndex値)。

注釈

このメソッドは、中断されないテキストの実行のみを返します。 以外 Text のシンボル型が、指定した方向の現在 TextPointer の に隣接している場合は、何も返されません。 同様に、テキストは次の非テキストシンボルまでしか返されません。

こちらもご覧ください

適用対象