日期:2014-05-16 浏览次数:20542 次
string str1 = @"<cc1:XYZ ID=""17_XYZ_ID"" runat=""server"" TableID=""17"" FieldName=""Title""></cc1:XYZ>";
//转img
string v1 = Regex.Replace(str1, @"(?i)<(cc1:(\S+))([^>]*?)></\1>", m =>
{
return string.Format(@"<img type=""{0}"" {1} src=""{2}""/>", m.Groups[2].Value, Regex.Replace(m.Groups[3].Value, @"(?i)\s+runat=""server""", ""), "images/textbox.gif");
});
//从img转cc1
string v2 = Regex.Replace(v1, @"(?i)<img([^>]*?)type=""([^'""]*?)""([^>]*?)>", m =>
{
return string.Format(@"<cc1:{0} {1}></ccs:{0}>",m.Groups[2].Value,Regex.Replace(m.Groups[1].Value+m.Groups[3].Value,@"(?i)\s+src=""images/textbox.gif""",@"runat=""server"""));
});
str=Regex.Replace(str,@"(?i)<cc1:(\S+)([^>]*?)></cc1:\1>","<img src=\"images/textbox.gif\" $2></img>");
str=Regex.Replace(str,@"(?i)<img\b([^>]*?)src=""images/textbox.gif""([^>]*?)type=""([^""]+)""([^>]*?)/?>","<cc1:$3 $1 runat=\"server\" $2 $4></cc1:$3>"