我正在处理代码,将html标签变为红色并在balck之间发送文本,但无法使其正常工作。 我一直在搞乱这段代码,但它只适用于开放和封闭标签的第一个实例。如果我转到下一行,我的标签不会变为红色,文本之间不会变黑。我使用相同类型的函数将html标签变为红色...下面的函数应该在标签之间将文本变为黑色。
Public Function FindBetweenTag(ByVal position As TextPointer,
ByVal startCharacter As String) As TextRange
While position IsNot Nothing
If position.GetPointerContext(LogicalDirection.Forward) =
TextPointerContext.Text Then
Dim textRun As String = position.GetTextInRun(LogicalDirection.Forward)
'find starting index of matching word
Dim indexInRun As Long = textRun.IndexOf(startCharacter)
Dim indexOfEndTag As Long = textRun.IndexOf("</p>")
If indexInRun >= 0 Then
Dim startPointer As TextPointer =
position.GetPositionAtOffset(indexInRun + startCharacter.Length + 1)
Dim endPointer As TextPointer =
startPointer.GetPositionAtOffset(indexOfEndTag)
Return New TextRange(startPointer, endPointer)
End If
End If
position = position.GetNextContextPosition(LogicalDirection.Forward)
End While
Return Nothing
End Function
有谁可以告诉我为什么这只适用于第一个实例?