เราไม่อยากโชว์เฉยๆ เเต่อยากทำให้มันเนียนขึ้นอีกนิด โดย HiligthKeyword ที่ตรงกับข้อความที่เรา search เข้าไป ใส่ใจในรายละเอียดเล็กน้อย จะทำให้เราเหนือกว่าได้ในที่สุด
Code: Select all
using System.Text;
public partial class bag : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string input = "เป็นโปรเเกรมเม่อร์ ทำดีเเค่เสมอตัว แม้ว่าวันได้พลาดขึ้นมาโดนฉะไม่ไว้หน้า";
string output = HiligthKeyword(input ,"ม");
Response.Write(output );
}
public static string HiligthKeyword(string message, string keyword)
{
string strRepalce = keyword;
Regex re = new Regex(keyword, RegexOptions.IgnoreCase);
string strMessageReturn = message;
MatchCollection matches = re.Matches(message);
foreach (Match match in matches)
{
strRepalce = "<# $>" + match.ToString() + "</#>";
strMessageReturn = strMessageReturn.Replace(match.ToString(), strRepalce);
}
strMessageReturn = strMessageReturn.Replace("$", "style='background : yellow'");
strMessageReturn = strMessageReturn.Replace("#", "font");
return strMessageReturn;
}
}