s.Replace(" ", " ");
s.Replace("\r", "<br>");
s.Replace("", "/>");
不知道是不是这个意思。

解决方案 »

  1.   

    我用你的方法试了.
    可是不能出现&nbsp;<br>等
    我原来是用asp的.
    是这样的
        s= replace(s, ">", "&gt;")
        s= replace(s, "<", "&lt;")
        s= Replace(s, CHR(32),"&nbsp;")
        s= Replace(s, CHR(13),"")
        s= Replace(s, CHR(10) & CHR(10),"</P><P>")
        s= s(fString, CHR(10),"<BR>")
      

  2.   

    在asp里面这是样的   
      re.Pattern="\[IMG](.[^\[]*)\[\/IMG]"
         strContent=re.Replace(strContent,"<IMG SRC=""$1"" border=0>")
    re.Pattern = "\[b](.[^\[]*)\[\/b]"
    strContent = re.Replace(strContent,"<b>$1</b>")
    re.Pattern = "\[FLASH](.[^\[]*)\[\/FLASH]"
    strContent = re.Replace(strContent,"<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$1""><PARAM NAME=quality VALUE=high><embed src=""$1"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$1</embed></OBJECT>")
      

  3.   

    可到c# aspx中不行了.
    高手解决.谢谢谢谢.
      

  4.   

    using System;
    using System.Text.RegularExpressions;class test
    {
    public static void Main ()
    {
    Regex re = new Regex("\\
    String strContent = "[img]http://wwww.test.com/test.jpg" alt="" />";
         strContent=re.Replace(strContent,"<IMG SRC=\"$1\" border=0>");
    Console.WriteLine(strContent);
    }
    }这段代码出来的结果是<IMG SRC="http://wwww.test.com/test.jpg" border=0>
    不知有没有帮助。
      

  5.   

    注意C#跟VB有几个很重要的问题:大小写,转义字符。
      

  6.   

    public string RecoverContent(string content)
    {
    string temp="";
    temp = content.Replace(" ","&nbsp;");
    temp = temp.Replace( Convert.ToString( ( char ) 13 ),"<br>");
    temp = temp.Replace( Convert.ToString( ( char ) 10 ),"&nbsp;");
    return temp;
    }
    上面的在关空格和回车符的转换,试试!
      

  7.   

    s.replace(">", "&gt;");
        s.replace("<", "&lt;");
        s.Replace(" ","&nbsp;");
        s.Replace("\n","");
        s.Replace("\n\r","</P><P>");
        s.Replace("\r","<BR>");
      

  8.   

    空格的替换问题已经解决.
    s= System.Text.RegularExpressions.Regex.Replace(s,@"\s", "&nbsp;");
    回车的总是测试中.
    谢谢你公主.
    一会给你加分.
    Regex re = new Regex("\\
    String strContent = "[img]http://wwww.test.com/test.jpg" alt="" />";
         strContent=re.Replace(strContent,"<IMG SRC=\"$1\" border=0>");
      

  9.   

    要是有转义字符,你可以在字符串前加上@,保留原来的格式.  如 @"E:/file/x.txt" =  "e://file//x.txt"
      

  10.   

    回车的:
    String strContent = "<img src=/>\r&nbsp;\r\rtest\r \r";
         strContent=Regex.Replace(strContent,"(\r){2}", "<p>");
         strContent=Regex.Replace(strContent,"\r", "<br>");
    Console.WriteLine(strContent);输出是<img src=/><br>&nbsp;<p>test<br> <br>
    不知可不可以。
      

  11.   

    不要转换了,这样就可以了:
    Regex re = new Regex("\\
    String strContent = "[IMg]http://wwww.test.com/test.jpg" alt="" />";
         strContent=re.Replace(strContent,"<IMG SRC=\"$1\" border=0>");
      

  12.   

    你应该先建一个好几行的大文本框.(能输入好几行文本的那种,在c#里叫什么我不知道)
    然后把里面输入文字再加回车.
    然后写语句把它的回车换成<br>.我试了一上午了.头大.脚软.  :)
    谢谢你噢.
      

  13.   

    这样可不可以:
    <%@ Page Language="C#" Debug="true" %>
    <%@ import namespace="System.Text.RegularExpressions" %>
    <HTML>
    <script runat="server">
    public void btnclick(Object sender, EventArgs e) {
    String str = txt.Text;    
    str=Regex.Replace(str,"(\r){2}", "<p>");
        str=Regex.Replace(str,"\r", "<br>");
    Response.Write(str);
    }
    </script>
    <HEAD>
    </HEAD>
    <body id="bd1" runat="server">
    <form id="f1" Target="_top" runat="server">
    <asp:TextBox id="txt" runat="server" textmode=MultiLine/>
    <asp:button id="btn" runat="server" onclick="btnclick" text="convert"/>
    </form>
    </body>
    </HTML>