Solved

Javascript String trim

Posted on 2014-09-29
4
209 Views
Last Modified: 2014-10-07
Hi Experts,

I am trying to trim string in javascript in both ways, but nothing works(IE9).

str.replace(/^\s+|\s+$/g, '')
str.trim()

what am I doing wrong?

thanks,
0
Comment
Question by:dkim18
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Rikin Shah
Comment Utility
Hi,

Check if you are having a special character and you think it is a space...
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
Comment Utility
Try the 'trim' demo on this page: http://www.w3schools.com/jsref/jsref_trim_string.asp
0
 
LVL 19

Accepted Solution

by:
Rikin Shah earned 250 total points
Comment Utility
Hi,

None of your statements assigns trimmed value to any variable.
Try-

str = str.replace(/^\s+|\s+$/g, '');
OR
str = str.trim();
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now