日期:2014-05-18 浏览次数:21126 次
using System.Text.RegularExpressions;
------解决方案--------------------
System.Text.RegularExpressions.Regex.Replace(str , @"\[#(.*?)\]", "[$1.gif]")
------解决方案--------------------
string str = "我想实现插入图片后在文本框中出现[#123123],所以文本中酒出现了[#123123]或者是[#1345]或者[#fjjk] ";
foreach (Match m in Regex.Matches(str, @"\[(?<text>[^\[\]]*)\]"))
{
str = str.Replace(m.Value, m.Groups["text"].Value.Replace("#", "") + ".gif");
}
Console.WriteLine(str);