bestlong 怕失憶論壇

標題: JavaScript 去除字串前後空白 [打印本頁]

作者: bestlong    時間: 2012-2-14 13:20     標題: JavaScript 去除字串前後空白

自己加寫函數,用正規表達式來處理
  1. /**
  2. * 去除字串左側空白
  3. */
  4. function LTrim(inStr)
  5. {
  6.   return inStr.replace(/^[\s]*/gi,"");
  7. }

  8. /**
  9. * 去除字串右側空白
  10. */
  11. function RTrim(inStr)
  12. {
  13.   return inStr.replace(/[\s]*$/gi,"");
  14. }
複製代碼





歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/) Powered by Discuz! X1.5