Solved

Javascript String trim

Posted on 2014-09-29
4
217 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
ID: 40349398
Hi,

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

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 40349404
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
ID: 40349722
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance for Office 365 6 50
how can i test my code? 1 40
Writing comments on <p></P> or paragraph 2 14
Javascript the "if condition with Or" 8 19
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

803 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