日期:2014-05-18 浏览次数:20749 次
using System; using System.Text; using System.Text.RegularExpressions; public class HighBright { public enum ChooseColorForText { Red, Green, Blue, Yellow, Black, Orange, Sienna, LightPink, } public enum ChooseSizeForText { A1 = 50, A2 = 40, A3 = 30, A4 = 20, A5 = 10, } public static string ChangeKeyWordColor(string strHtml, string strKeyWord, ChooseColorForText color, ChooseSizeForText size) { return Regex.Replace(strHtml, strKeyWord, "<font color=\"" + color + "\"><b style=\"font-size:" + (int)size + "px;\">" + strKeyWord+ "</b></font>\n", RegexOptions.IgnoreCase); } } Response.Write(HighBright.ChangeKeyWordColor("abc", "a", HighBright.ChooseColorForText.Blue, HighBright.ChooseSizeForText.A1)); //显示结果如下:
><font color="Blue"><b style="font-size: 50px;">a</b></font> bc