Syntax Highlighter

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Hi all,
This is my code which detects words and put it between a BB code.

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void button_Convert_Click(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; string[]
keyWords =
{
<span style="color:#A31515; "if",
<span style="color:#A31515; "new",
<span style="color:#A31515; "return" ,
<span style="color:#A31515; "switch",
<span style="color:#A31515; "char",
<span style="color:#A31515; "int",
<span style="color:#A31515; "case",
<span style="color:#A31515; "while",
<span style="color:#A31515; "do",
<span style="color:#A31515; "sizeof",
<span style="color:#A31515; "tagof",
<span style="color:#A31515; "true",
<span style="color:#A31515; "false",
<span style="color:#A31515; "default",
<span style="color:#A31515; "for",
<span style="color:#A31515; "register",
<span style="color:#A31515; "else",
<span style="color:#A31515; "else if",
<span style="color:#A31515; "else return",
<span style="color:#A31515; "static",
<span style="color:#A31515; "const",
<span style="color:#A31515; "public",
<span style="color:#A31515; "enum",
<span style="color:#A31515; "struct",
<span style="color:#A31515; "class",
<span style="color:#A31515; "using",
<span style="color:#A31515; "bool",
<span style="color:#A31515; "float",
<span style="color:#A31515; "class",
<span style="color:#A31515; "private",
}
;
<span style="color:Blue; string
inputText = textBox_Input.Text;

<span style="color:Blue; foreach (<span style="color:Blue; string word <span style="color:Blue; in keyWords)
{
inputText = inputText.Replace(word, <span style="color:#A31515; "" + word + <span style="color:#A31515; "");
}
textBox_Output.Text = <span style="color:#A31515; "" + inputText + <span style="color:#A31515; "";
}
[/code]

Well this works perfect but its not %100 like I want.
For example I have random as text in my input. It will put the do of ran do m between the BB code because keyWord "do" is in the list. How can I solve this?
Regards

View the full article
 
Back
Top