2012-05-30 37 views
7

Olası Çoğalt:
How do I trim a string in javascript?Bir dizeden son ve ilk boşluklar nasıl kaldırılır?

Ben sadece son ve genel dizesinden ilk boşlukları kaldırmak gerekir.

Örnek:

var str = " hello world "; // become "hello world" 
var str = "ehi, do you come from ? "; // become "ehi, do you come from ?" 
var str = "I am from Cina"; // remain "I am from Cina" 

Bunu nasıl yapabilirim?

+2

Ve http://stackoverflow.com/questions/196925/what-is-the-best-way-to-trim-in- javascript –

+0

Buna kırpma denir. Http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript/8522376#8522376 veya http://stackoverflow.com/questions/498970/how-do-i sayfasına bakın. -Trim-a-string-in-javascript – sgowd

cevap

10

trim from jQuery, aradığınız şeydir.

$.trim(' string with spaces at the ends ');

Veya düz javascript:

' string with spaces at the ends '.trim()

İlgili konular