2012-05-30 12 views
7

संभव डुप्लिकेट:
How do I trim a string in javascript?स्ट्रिंग से अंतिम और प्रथम रिक्त स्थान को कैसे निकालें?

मैं केवल पिछले और एक सामान्य स्ट्रिंग से पहले रिक्त स्थान को दूर करने की जरूरत है।

उदाहरण:

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" 

मैं ऐसा कैसे कर सकता है?

+2

और http://stackoverflow.com/questions/196925/what-is-the-best-way-to-trim-in- जावास्क्रिप्ट –

+0

इसे ट्रिमिंग कहा जाता है। Http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript/8522376#8522376 या http://stackoverflow.com/questions/498970/how-do-i देखें -trim एक स्ट्रिंग में जावास्क्रिप्ट – sgowd

उत्तर

10

trim from jQuery वह है जिसे आप ढूंढ रहे हैं।

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

या सादे जावास्क्रिप्ट:

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

संबंधित मुद्दे