<span>中国美术大学 </span> 2009中国美术大学招生简章
把前面的学校名字替换掉后面的标题中的字符
学校名称是从数据库里取得,标题也是从数据库取得。
效果如
2009<span style=color:red>中国美术大学</span>招生简章
怎么做啊
有没有这样一个函数??
求
动态实现替换字符串
把前面的学校名字替换掉后面的标题中的字符
学校名称是从数据库里取得,标题也是从数据库取得。
效果如
2009<span style=color:red>中国美术大学</span>招生简章
怎么做啊
有没有这样一个函数??
求
动态实现替换字符串
string title = "2009中国美术大学招生简章";
string sname = "中国美术大学";title = title.Replace(sname,"<span style=color:red>"+sname+"</span>");//你要的结果
如果是显示时处理楼上的办法吧
页面部分放:
<asp:Label ID="sname" runat="server"></asp:Label>.cs文件里写上:
string s1 = "2009中国美术大学招生简章";
string s2 = "中国美术大学";//数据库得到部分 sname.Text.Replace(s1," <span style=color:red>"+s2+" </span>");//你要的结果
string School= "中国美术大学"; title = title.Replace(School," <span style=color:red>"+School+" </span>");
string str2 = "2009中国美术大学招生简章";
string str3=str2.Replace(str1.Replace("<span>","").Replace("</span>",""),str1.Replace("<span>","<span style=color:red>"));
string str1 = "<span>中国美术大学 </span> 2009中国美术大学招生简章 ";
string str2 = Regex.Replace(str1, @"<span>(.*?)\s*</span>\s*(.*?)\1(.*?)", "$2<span style=color:red>$1</span>$3");