Trim function in javascript

Posted on 2000-05-10
Last Modified: 2012-05-04
what is the function to trim a string,
which we can trim in asp
Question by:gopigoud
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 22

Expert Comment

ID: 2795805
ther eis no Trim-a-like function in javascript. You should make it yourself.

Accepted Solution

wailqill earned 50 total points
ID: 2795819
You can paste this into your code:

String.prototype.trim=function() {
      return this.rtrim().ltrim()
String.prototype.ltrim=function() {
      return this.replace(/^\s*/,'')
String.prototype.rtrim=function() {
      return this.replace(/\s*$/,'')

then you can use this syntax with every string-object U have on your page:

stringname.ltrim() // left trim
stringname.rtrim() // right trim

or even "  dsaf as ".trim()

Expert Comment

ID: 5187939
the above code helps

Thanks a lot..

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 43
need help with share buttons 11 73
Why is my $_POST not going to results page 10 41
Collapse in/out from a "a href" each row containing different id 5 47
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question