[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Trim function in javascript

Posted on 2000-05-10
3
Medium Priority
?
409 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

649 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