Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169736
  • Last Modified:

trim in javascript

how can i do that?
i need just like in VB : trim(str)


e.
0
eladr
Asked:
eladr
1 Solution
 
knightEknightCommented:
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
0
 
knightEknightCommented:

var str = "  this is a test   ";

str = trim(str);
0
 
knightEknightCommented:
the most convenient way is to use the function as noted above, but you can simply do this:

   var str = "  this is a test   ";

   str = str.replace(/^\s*|\s*$/g,"");
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
waqar2004Commented:
KnightEknight

good work.
0
 
rkarthik29Commented:
var str = "  this is a test   ";

str = Trim(str);
0
 
knightEknightCommented:
the function is case sensitive

str = trim(str);


:)
0
 
stevenlevithanCommented:
This post compares a variety of ways to <a href="http://blog.stevenlevithan.com/archives/faster-trim-javascript">trim in JavaScript</a>.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now