VB.NET语法在文本

时间:2016-01-27 03:17:12

标签: vb.net visual-studio

我刚刚开始在VB.NET中查看语法高亮的一些示例,并且它的工作非常不错。但是,有没有办法检查另一个文本中的某些文本?例如,如果我希望" "突出显示为橙色,那么工作正常。但是如果我希望" "内的任何文字都是蓝色的呢?有没有办法只检查里面的文字?我目前的代码(不是我的,来自here

Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
    ' Dim 
    Dim brackets As New List(Of String)
    ' AQUA
    brackets.Add("<")
    brackets.Add(">")
    brackets.Add("/>")
    brackets.Add("</")

    Dim tags As New List(Of String)
    ' LIME GREEM
    tags.Add("html")
    tags.Add("title")
    tags.Add("head")

    If RichTextBox1.Text.Length > 0 Then
        Dim selectStart As Integer = RichTextBox1.SelectionStart
        RichTextBox1.Select(0, RichTextBox1.Text.Length)
        RichTextBox1.SelectionColor = Color.Black
        RichTextBox1.DeselectAll()

        For Each oneWord As String In brackets
            Dim pos As Integer = 0
            Do While RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
                pos = RichTextBox1.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
                RichTextBox1.Select(pos, oneWord.Length)
                RichTextBox1.SelectionColor = Color.Aqua
                pos += 1
            Loop
        Next

        For Each tagWord As String In tags
            Dim pos As Integer = 0
            Do While RichTextBox1.Text.ToUpper.IndexOf(tagWord.ToUpper, pos) >= 0
                pos = RichTextBox1.Text.ToUpper.IndexOf(tagWord.ToUpper, pos)
                RichTextBox1.Select(pos, tagWord.Length)
                RichTextBox1.SelectionColor = Color.LimeGreen
                pos += 1
            Loop
        Next

        RichTextBox1.SelectionStart = selectStart
    End If
End Sub

我没有使用&#34; &#34;例如,但是我们想要用&lt;取代。有办法吗?

0 个答案:

没有答案