用正则表达式
[img]http://www.baidu.com/aa.jpg[img]
变成
<img>http://www.baidu.com/aa.jpg[img]
谁有基于c#的简易发帖编辑器,给我来一个地址,求各位大哥了

解决方案 »

  1.   

    string strReg=@"([\[]img[\]])([^[\n]*)([\[]img[\]])";
    string strText=@"[img]http://1www.basidu.com/aa.jpg[img][img]http://4www.bdaidu.com/aa.jpg[img]";
    System.Text.RegularExpressions.MatchCollection _regc=Regex.Matches(strText,strReg,RegexOptions.Multiline);
    foreach(Match match in _regc)
    {
    strText=strText.Replace(match.Value ,@"<img>"+match.Groups[2].Value+match.Groups[3].Value );
    }
    MessageBox.Show(strText);
      

  2.   

    string strReg=@"([\[]img[\]])([^[\n]*)([\[]img[\]])";
    string strText=@"[img]http://1www.basidu.com/aa.jpg[img][img]http://4www.bdaidu.com/aa.jpg[img]";
    System.Text.RegularExpressions.MatchCollection _regc=Regex.Matches(strText,strReg,RegexOptions.Multiline);
    foreach(Match match in _regc)
    {
    strText=strText.Replace(match.Value ,@"<img>"+match.Groups[2].Value+match.Groups[3].Value );
    }
    MessageBox.Show(strText);