TextPointer.GetTextInRun 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回与当前 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 实例之间的所有文本的字符串串联。
虽然该示例可用于提取两个 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.
注解
此方法仅返回不间断的文本运行。 如果指定的方向上与当前TextPointer相邻的符号类型以外的Text任何符号类型,则不返回任何内容。 同样,文本仅返回到下一个非文本符号。
另请参阅
适用于
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 或大于 Length 。textBuffer
-或-
count小于 0 或大于 (. 减号startIndex) 中的textBuffertextBuffer剩余空间。Length
注解
此方法仅返回不间断的文本运行。 如果指定的方向上与当前TextPointer相邻的符号类型以外的Text任何符号类型,则不返回任何内容。 同样,文本仅返回到下一个非文本符号。