• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Javascript String trim

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
dkim18
Asked:
dkim18
  • 2
2 Solutions
 
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Hi,

Check if you are having a special character and you think it is a space...
0
 
Dave BaldwinFixer of ProblemsCommented:
Try the 'trim' demo on this page: http://www.w3schools.com/jsref/jsref_trim_string.asp
0
 
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now