一个 Regex 中的问题,在线等~~~
怎么用C#.net转成
<img scr='/upload/20131228/a.gif'/>
我只知是用
Regex中的方法,那位高手能教一下,
给个小例子~~~~~~~~~谢谢!! --------------------编程问答-------------------- 试一下:
string sourceString = @"";
string pattern = @"(?<=\[img\])[\s\S]+?(?=\[/img\])";
System.Text.RegularExpressions.Match result = Regex.Match(sourceString,pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase|System.Text.RegularExpressions.RegexOptions.Multiline);
if (result.Success)
{
//提示正确信息
//WL("正确:" + result.Groups[1].Value);//输出
WL("正确:" + result.Value);//输出
} --------------------编程问答-------------------- 方法太多,几个比较笨的
string oldStr = "";
string newStr1 = oldStr.Replace("[img]", "<img src='").Replace("[/img]", "' />");
string newStr2 = Regex.Replace(Regex.Replace(oldStr, "[img]", "<img src='"), "[/img]", "' />");
string newStr3 = String.Format("<img src='{0}' />", Regex.Match(oldStr, @"^\[img\](?<1>\S|\s*)\[/img\]$").Groups[1])); --------------------编程问答-------------------- 谢谢~~~~~~~~ --------------------编程问答-------------------- 我是做个基本的编辑器,如果有,现成的类给个我用用~呵呵,以上的方法不太合适
补充:.NET技术 , ASP.NET