如有以下文本:
string str = @ " <table ……> <tr> <td colspan= "3 "> [m.v] </td> </tr> <tr> <td> [m.v] </td> <td> [m.v] </td> <td> [m.v] </td> </tr> <tr> <td> [m.v] </td> <td> [m.v] </td> <td> [m.v] </td> </tr> </table> ";
string msg = null; string ptn = "[m.v] "; for(int i=0; i <100; i++) { // 如将上面文本的标签分别用i来替换(实际应用中,我有其它的数据来替换,使用i替换只是一个例子)。如何使用正则表达式来实现。谢谢。 }
哈哈,谢谢zswang,根据你的指导,我已经解决了,非常感谢。
MatchCollection vMatches = Regex.Matches(str, @ "(? <ts> \[m.v\]) "); for (int i = vMatches.Count - 1; i > = 0; i--) { str = str.Remove(vMatches[i].Groups[ "ts "].Index, vMatches[i].Groups[ "ts "].Value.Length); str = str.Insert(vMatches[i].Groups[ "ts "].Index, s[i]); }
采集来源
http://topic.csdn.net/u/20070228/16/46e3ecea-63b0-4250-8b38-49bd5e89f8ae.html