主要功能是把c#的文本代码转换成有颜色的html代码
实在是很笨一个类,只有两种着色模式(把关键字变蓝,把字符串变褐",但还能用...反正挺简单,把源代码也发出来,下面的源代码就是用这个类着色过的
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace d_BlogCodeHelper
{
public class ColorCodes
{
public string Font
{
get { return font; }
set { font = value; }
}
public string FontSize
{
get { return fontSize; }
set { fontSize = value; }
}
public string BlueColor
{
get { return blueColor; }
set { blueColor = value; }
}
public string BrownColor
{
get { return brownColor; }
set { brownColor = value; }
}
public string GreenColor
{
get { return greenColor; }
set { greenColor = value; }
}
public string BrownAndBlueWords(string oldtext)
{
StringBuilder text = new StringBuilder(oldtext);
text.Replace(" ", " ");
text.Replace("<", "<");
text.Replace(">", ">");
text.Replace("/n", "<br/>");
text.Insert(0, "<font face='" + Font + "'><font size='" + FontSize + "'>");
text.Append("</font>");
foreach (string nowWord in blueWords)
{
text.Replace(nowWord, "<font color='#" + blueColor + "'>" + nowWord + "</font>");
}
Regex findString = new Regex("/"(?.)*?/"");
MatchCollection allStrings = findString.Matches(text.ToString());
foreach (Match oneString in allStrings)
{
text.Replace(oneString.Value, "<font color='#" + brownColor + "'>" + oneString.Value + "</font>");
}
return text.ToString();
}
public string BlueWords(string oldtext)
{
StringBuilder text = new StringBuilder(oldtext);
text.Replace(" ", " ");
text.Replace("<", "<");
text.Replace(">", ">");
text.Replace("/n", "<br/>");
text.Insert(0, "<font face='" + Font + "'><font size='"+FontSize+"'>");
text.Append("</font>");
foreach (string nowWord in blueWords)
{
text.Replace(nowWord, "<font color='#"+blueColor+"'>" + nowWord + "</font>");
}
return text.ToString();
}
private string font = "Tahoma";
private string fontSize="1";
private string blueColor="0000ff";
private string greenColor="008800";
private string brownColor = "a31515";
//下面一个储存所有C#关键字的数组,但是对于在字符串里出现的关键字,这个类处理的还不够好
private string[] blueWords ={ }
}