如有字符
"  \r  \r\n  \n  哈 \r  \r\n 哈  \r \r\n  "
最后变成
"哈 \r  \r\n 哈"
也就像string的trim方法,只不过现在还有去掉换行符谢谢

解决方案 »

  1.   

    string retVal = string.Replace(" ", string.Empty);
    retVal  = retVal .Replace("\n", string.Empty);
      

  2.   

    <textarea   id=mm   style="width:   400;   height:   200">   
      aa   bb   cc   dd           
      ssfd     dd   s                     
      ddddddd     cc       
                
      </textarea><br>   
      <input   type=button   value=change   onclick="cc()">     <SCRIPT   LANGUAGE="JavaScript">   
      function   cc()   
      {   
          var s=document.getElementById("mm").value;   
      alert(s.replace(/\s*(.*?)\s*(\r\n)\s*/mg,"$1$2"));
      }   
      </SCRIPT>
      

  3.   

    c#的trim就是让
    "  \r  \r\n  \n  哈 \r  \r\n 哈  \r \r\n  " 
    最后变成 
    "哈 \r  \r\n 哈" 

    谢谢
      

  4.   


    s.replace(/(^\s+|\s+$)/g,"")
      

  5.   

         Removes all occurrences of white space characters from the  beginning and end of this instance.
         删除前后留白处的字符,并不仅仅是空格,上面是trim()的注释。(c#)