[정규식] Replace~
-> TextBox 2개 , 버튼 1개
변환 대상 문자열 : "<div>나&너&우리</div>"
음 훈스에 올렸는데 더 간단한것이..
소류님 글...
01. 참조에 System.Web을 추가합니다.
02. MessageBox.Show(System.Web.HttpUtility.HtmlEncode("<>&"));
// 이하 소스~~~
private void button1_Click(object sender, EventArgs e)
{
string pttr = "<|&|>";
Regex rx = new Regex(pttr);
this.textBox2.Text = rx.Replace(this.textBox1.Text, new MatchEvaluator(ReplaceString));
}
//http://msdn.microsoft.com/en-us/library/cft8645c.aspx
static string ReplaceString(Match m)
{
string mString = m.ToString();
switch (mString)
{
case "<":
mString = "<";
break;
case ">":
mString = ">";
break;
case "&":
mString = "&";
break;
}
return mString;
}