将字符串中指定字符替换成其他不同字符

 

public static int i = 0; private void dd() { string sone, stwo; sone = "afasf<span style="color:red" mce_style="color:red">{A}</span>asd<span style="color:red" mce_style="color:red">{A}</span>fdd<span style="color:red" mce_style="color:red">{A}</span>ddd<span style="color:red" mce_style="color:red">{A}</span>----<span style="color:red" mce_style="color:red">{A}</span>asfasdfasd<span style="color:red" mce_style="color:red">{A}</span>54646<span style="color:red" mce_style="color:red">{A}</span>"; stwo = "{A}"; Regex r = new Regex(stwo); MatchEvaluator myEvaluator = new MatchEvaluator(ReplaceCC); Response.Write("原 字 符 串:" + sone+"<br/>"); sone = r.Replace(sone, myEvaluator); Response.Write("替换后字符串:"+sone); } public string ReplaceCC(Match m) { List<string> l = new List<string>(); l.Add("我"); l.Add("是"); l.Add("中"); l.Add("国"); l.Add("人"); if (i < l.Count) { i++; } else { i = 1; } return l[i-1].ToString(); }

你可能感兴趣的:(String,regex)