有一个多行TextBox,现要把所输入的内容插入数据库,然后在另外的页面显示出来。
请问:如何得到换行符,以便把它改成<br>插入数据库,如何得到空格,以便把它改成&nbsp;插入数据库?

解决方案 »

  1.   

    str.Replace(" ", "&nbsp;").Replace("\r\n", "<br>")
      

  2.   

    好像不行,我这样用
    TextBox tb;
    string str=tb.Text;
    str.Replace(" ", "&nbsp;").Replace("\r\n", "<br>")
    然后就插入到数据库,但是数据库里依然没有改变什么
      

  3.   

    假设你的textBox的id是textBox1string str = textBox1.Text.Replace(" ", "&nbsp;").Replace("\r\n", "<br>");
      

  4.   

    你说的方法是不行的!我这样做后插入数据库后仍然没有&nbsp;和<br>,依然是空格,和一长串空格(换行)
      

  5.   


    string str = textBox1.Text.Replace(" ", "&nbsp;").Replace("\r\n", "<br>");
      

  6.   

    看看你插入的sql语句值是textBox1.Text还是str?
      

  7.   

    问题是,好像Textbox1中,就算我回车,他的值也不是\r\n,而是一长串空格!