Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. RTF/Regex Question

RTF/Regex Question

Scheduled Pinned Locked Moved C#
questiondatabaseregex
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Mike HankeyM Offline
    Mike HankeyM Offline
    Mike Hankey
    wrote on last edited by
    #1

    Hello, I'm trying to highlight selected text in a RichTextBox Control. I want to do this by using the RTF control code \cbn where n = index. As I understand you prefix the selected text with a \cbn code to change the background color to the highlight color then Postfix it with another \cbn code to reset color back. See COMMENT BELOW for full description //RTF Color codes with indices into Color Table private const string clrDefault = @"\cf1 "; private const string clrKeyword = @"\cf2 "; private const string clrLiteral = @"\cf3 "; private const string clrOutlining = @"\cf4 "; private const string clrComment = @"\cf5 "; private const string clrSelect = @"\cf6 "; //The actual individual entries in the Coor Table protected static string colorDefault = @"\red0\green0\blue0;"; protected static string colorKeyword = @"\red15\green0\blue255;"; protected static string colorLiteral = @"\red200\green105\blue36;"; protected static string colorOutlining = @"\red27\green175\blue78;"; protected static string colorComment = @"\red160\green160\blue160;"; protected static string colorSelect = @"\red90\green90\blue90;"; //Code to build the Color Table string protected static string rtfColorTable = @"{\colortbl ;" + colorDefault + colorKeyword + colorLiteral + colorOutlining + colorComment + colorSelect + @"}"; public static void HighlightSelection(RichTextBox rtb, string selTxt) { string result = rtb.Rtf; //Replaces existing colorTable with mine result = CreateColorTable(result); Regex r = new Regex(selTxt); // COMMENT BELOW //If I use clrSelect + selText + clrDefault // i.e. @"\cf6 " + selText + @"\cf1 " //The proper keywords foreColor changes to gray. //But when I use the \cbn equiv. it doesn't?? result = r.Replace( result, @"\cb6 " + selTxt + @"\cb1 "); rtb.Rtf = result; } Thanks for your time! Mike P.S. Does anyone know a good Regex reference?

    Light travels faster than sound. That's why some people appear right until you hear them speak.

    S 1 Reply Last reply
    0
    • Mike HankeyM Mike Hankey

      Hello, I'm trying to highlight selected text in a RichTextBox Control. I want to do this by using the RTF control code \cbn where n = index. As I understand you prefix the selected text with a \cbn code to change the background color to the highlight color then Postfix it with another \cbn code to reset color back. See COMMENT BELOW for full description //RTF Color codes with indices into Color Table private const string clrDefault = @"\cf1 "; private const string clrKeyword = @"\cf2 "; private const string clrLiteral = @"\cf3 "; private const string clrOutlining = @"\cf4 "; private const string clrComment = @"\cf5 "; private const string clrSelect = @"\cf6 "; //The actual individual entries in the Coor Table protected static string colorDefault = @"\red0\green0\blue0;"; protected static string colorKeyword = @"\red15\green0\blue255;"; protected static string colorLiteral = @"\red200\green105\blue36;"; protected static string colorOutlining = @"\red27\green175\blue78;"; protected static string colorComment = @"\red160\green160\blue160;"; protected static string colorSelect = @"\red90\green90\blue90;"; //Code to build the Color Table string protected static string rtfColorTable = @"{\colortbl ;" + colorDefault + colorKeyword + colorLiteral + colorOutlining + colorComment + colorSelect + @"}"; public static void HighlightSelection(RichTextBox rtb, string selTxt) { string result = rtb.Rtf; //Replaces existing colorTable with mine result = CreateColorTable(result); Regex r = new Regex(selTxt); // COMMENT BELOW //If I use clrSelect + selText + clrDefault // i.e. @"\cf6 " + selText + @"\cf1 " //The proper keywords foreColor changes to gray. //But when I use the \cbn equiv. it doesn't?? result = r.Replace( result, @"\cb6 " + selTxt + @"\cb1 "); rtb.Rtf = result; } Thanks for your time! Mike P.S. Does anyone know a good Regex reference?

      Light travels faster than sound. That's why some people appear right until you hear them speak.

      S Offline
      S Offline
      subrata jana
      wrote on last edited by
      #2

      http://www.ultrapico.com/Expresso.htm Download the tool , its a tool to test regular expression and with few example of regex

      Mike HankeyM 1 Reply Last reply
      0
      • S subrata jana

        http://www.ultrapico.com/Expresso.htm Download the tool , its a tool to test regular expression and with few example of regex

        Mike HankeyM Offline
        Mike HankeyM Offline
        Mike Hankey
        wrote on last edited by
        #3

        Thanks for the link...Expresso is much better than the one I was using. Thanks Mike

        Light travels faster than sound. That's why some people appear right until you hear them speak.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups