I came across this syntax highlighting c# tutorial and i decided to write my own version for one of my project.
This is the method responsible for highlighting the syntax in a given line (from rtb)
// Process This Line Of Text
private void ProcessLine()
{
// Add Keywords - TODO
_keyword_list.Add("xml");
// Set Color Parameter - TODO
_keyword_color = Color.Red;
// Compile RegEx String
string _temp_keyword_list = "";
for (int i = 0; i < _keyword_list.Count; i++)
{
// Update _temp_keyword_list String
_temp_keyword_list += "\\b" + _keyword_list[i] + "\\b";
if (i != (_keyword_list.Count - 1))
{
_temp_keyword_list += "|";
}
}
// Save Position & Make Curent Line's Text Black Color
int _position = Selectionstart;
Selectionstart = _line_start;
SelectionLength = _line_length;
SelectionColor = Color.Black;
// Create A RegEx Object
Regex _reg_keywords = new Regex(_temp_keyword_list, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match _reg_match;
// Process Every Matched Words
for (_reg_match = _reg_keywords.Match(_current_line); _reg_match.Success; _reg_match = _reg_match.NextMatch())
{
int _temp_start = _line_start + _reg_match.Index;
int _temp_length = _reg_match.Length;
Selectionstart = _temp_start;
SelectionLength = _temp_length;
SelectionColor = _keyword_color;
}
// Get & Set Updated Data
Selectionstart = _position;
SelectionLength = 0;
SelectionColor = Color.Black;
_current_selection = _position;
}
When i run my test application, the syntax highlighting works fine like this -> http://img27.imagesh...96/91309633.png
The thing is, syntax highlighting only works if there are spaces between my keywords. Take a look at this -> http://i40.tinypic.com/2n176ep.png
see what i mean?
My question was, is it possible to highlight a keyword regardless what's in front or back of the matched text?
for example:
text on my rtb = abcd123
one of my keyword = cd1
when the regex is matched, the text should look like this in the rtb : abcd123
This post has been edited by Latheesan: 07 May 2009 - 12:39 AM

New Topic/Question
Reply



MultiQuote


|