输入hello ,把字符中的 hello 前后加<b>和 </b> ,字符中的hello包括多种情况 Hello,heLLo... 输入hello ,把字符中的 hello 前后加<b>和</b> ,字符中的hello包括多种情况 Hello,heLLo...这里hello 是变量,hello是举例。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String a = "hellosjofdsjiHello";System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[hH][eE][lL]{2}[oO]");System.Text.RegularExpressions.MatchCollection matchs = regex.Matches(a);a = regex.Replace(a, "***");regex = new System.Text.RegularExpressions.Regex("[*]{3}");for (int i = 0; i < matchs.Count; i++){ a = regex.Replace(a, "<b>" + matchs[i].Value + "</b>", 1);} "<b>"+Hello+"</b>"也能解决啊 硬规则:最前面+<b>,替换成</b>,<b>末尾+</b> System.Data.Linq.DataContext不包含采用“0”个参数的构造函数 vs2010开发web程序怎么判断程序运行的状态 循环显示数据问题 关于在页面动态显示图片 怎样限制文件上传类型 datalist中绑定ascx,查询后再绑定后图片显示问题 net1.1和2.0可以共存吗? Asp.net web api 开发遇到的一个问题 NTKO如何一个页面添加多个? 请问高手,asp.net如何运行? 页面为什么会闪动? 求助GridView里一个奇怪的问题
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[hH][eE][lL]{2}[oO]");
System.Text.RegularExpressions.MatchCollection matchs = regex.Matches(a);
a = regex.Replace(a, "***");
regex = new System.Text.RegularExpressions.Regex("[*]{3}");
for (int i = 0; i < matchs.Count; i++)
{
a = regex.Replace(a, "<b>" + matchs[i].Value + "</b>", 1);
}
最前面+<b>
,替换成</b>,<b>
末尾+</b>