1

我正在研究将html标签变为红色和黑色之间的文本的代码,但无法使其正常工作。我一直在弄乱这段代码,但它只适用于打开和关闭标签的第一个实例。如果我转到下一行,我的标签不会变成红色,并且中间的文本不会变成黑色。我使用相同类型的函数将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

谁能告诉我为什么这只适用于第一个实例?

4

0 回答 0