我想用replace()函数将字符串中的空格用“&nbsp;”取代,回车换行用“<br>”取代
但总是实现不了
请大家帮帮忙!
谢谢!

解决方案 »

  1.   

    Replace(string," ","&nbsp")
    Replace(string,"\n","<Br>")试试!
      

  2.   

    有个笨方法,new个足够大(-_-)的空间
    遍历源串,不是空格或回车换行的就直接拷贝到新串
    否则就将对应的字符写入新串。没用过CString的Replace,你看看MSDN怎么用。
      

  3.   

    -------From MSDN--------//First example, with old and new equal in length.CString strZap("C--");
    int n = strZap.Replace('-', '+');
    ASSERT(n == 2);
    ASSERT(strZap == "C++");//Second example, old and new are of different lengths.CString strBang("Everybody likes ice hockey");
    n = strBang.Replace("hockey", "golf");
    ASSERT(n == 1);
    n = strBang.Replace("likes", "plays");
    ASSERT(n == 1);
    n = strBang.Replace("ice", NULL);
    ASSERT(n == 1);
    ASSERT(strBang == "Everybody plays  golf");// note that you now have an extra space in your
    // sentence. To remove the extra space, include it 
    // in the string to be replaced, i.e.,"ice ".