?
Solved

Trim function in javascript

Posted on 2000-05-10
3
Medium Priority
?
408 Views
Last Modified: 2012-05-04
what is the function to trim a string,
which we can trim in asp
0
Comment
Question by:gopigoud
[X]
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
3 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 2795805
ther eis no Trim-a-like function in javascript. You should make it yourself.
0
 
LVL 1

Accepted Solution

by:
wailqill earned 150 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.trim()
or
stringname.ltrim() // left trim
or
stringname.rtrim() // right trim

or even "  dsaf as ".trim()
0
 

Expert Comment

by:qader99
ID: 5187939
the above code helps

Thanks a lot..
0

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

770 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