Back to the HTML color coding

I want to thank Chris for his help last time, but it seems that this problem needs to be revisited. The code you gave me works great chris, for others who want to see it go here .
The one problem I had was when i was turning it into a function. I was able to make a function that would just turn "" a color. I wanted to include ALL HTML tags(that is my fault for not explaining fully). I thought that this could be done easily with an array, but that did not work. Possibly if there was someway to turn this charactor: '<' and all things inbettween it untill this charactor '>' that would work. I have tried to solve this on my own, but have failed. Possibly it could be done with a loop, but i am bad with them. :( Thanks to anyone who can help.

Comments

  • Hey,

    Perhaps this is more what you're looking for. The following code uses
    the Regex class. Basically the class allows for pattern searching in regular expressions. I added the following to my code
    [code]
    Imports System.Text.RegularExpressions
    [/code]

    Then in some event you can try the following code

    [code]
    Dim oRegex As Regex
    Dim oMatches As MatchCollection 'represents multiple matches
    Dim oMatch As Match

    oMatches = oRegex.Matches(txtRich.Text, "<(/|w).*>")
    'txtRich is the RichTextbox
    'the pattern parameter looks for....
    ' an open angle bracket followed by
    ' a forward slash (represents itself) OR
    ' any word character (represented by w) followed by
    ' anything else (represented by .*) followed by
    ' an closed angle bracket
    ' Ultimately, this pattern will find , ,
    ' etc. but will not find the "not equal" operator <>
    ' For more information on Regex, F1 on the Regex declaration
    ' is pretty helpful
    For Each oMatch In oMatches
    txtRich.Select(oMatch.Index, oMatch.Length)
    txtRich.SelectionColor = Color.Red
    Next
    'Set Color after the text to black
    txtRich.Select(txtRich.TextLength + 1, 1)
    txtRich.SelectionColor = Color.Black
    [/code]

    Hope this helps.
    Cheers,

    Chris

    : I want to thank Chris for his help last time, but it seems that this problem needs to be revisited. The code you gave me works great chris, for others who want to see it go here .
    : The one problem I had was when i was turning it into a function. I was able to make a function that would just turn "" a color. I wanted to include ALL HTML tags(that is my fault for not explaining fully). I thought that this could be done easily with an array, but that did not work. Possibly if there was someway to turn this charactor: '<' and all things inbettween it untill this charactor '>' that would work. I have tried to solve this on my own, but have failed. Possibly it could be done with a loop, but i am bad with them. :( Thanks to anyone who can help.
    :

  • Thank you very much chris. That was great code, and it taught me about regex. Its always good to learn something new. Thanks agian,
    Adam Botsford

    : Hey,
    :
    : Perhaps this is more what you're looking for. The following code uses
    : the Regex class. Basically the class allows for pattern searching in regular expressions. I added the following to my code
    : [code]
    : Imports System.Text.RegularExpressions
    : [/code]
    :
    : Then in some event you can try the following code
    :
    : [code]
    : Dim oRegex As Regex
    : Dim oMatches As MatchCollection 'represents multiple matches
    : Dim oMatch As Match
    :
    : oMatches = oRegex.Matches(txtRich.Text, "<(/|w).*>")
    : 'txtRich is the RichTextbox
    : 'the pattern parameter looks for....
    : ' an open angle bracket followed by
    : ' a forward slash (represents itself) OR
    : ' any word character (represented by w) followed by
    : ' anything else (represented by .*) followed by
    : ' an closed angle bracket
    : ' Ultimately, this pattern will find , ,
    : ' etc. but will not find the "not equal" operator <>
    : ' For more information on Regex, F1 on the Regex declaration
    : ' is pretty helpful
    : For Each oMatch In oMatches
    : txtRich.Select(oMatch.Index, oMatch.Length)
    : txtRich.SelectionColor = Color.Red
    : Next
    : 'Set Color after the text to black
    : txtRich.Select(txtRich.TextLength + 1, 1)
    : txtRich.SelectionColor = Color.Black
    : [/code]
    :
    : Hope this helps.
    : Cheers,
    :
    : Chris
    :
    : : I want to thank Chris for his help last time, but it seems that this problem needs to be revisited. The code you gave me works great chris, for others who want to see it go here .
    : : The one problem I had was when i was turning it into a function. I was able to make a function that would just turn "" a color. I wanted to include ALL HTML tags(that is my fault for not explaining fully). I thought that this could be done easily with an array, but that did not work. Possibly if there was someway to turn this charactor: '<' and all things inbettween it untill this charactor '>' that would work. I have tried to solve this on my own, but have failed. Possibly it could be done with a loop, but i am bad with them. :( Thanks to anyone who can help.
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories