/    Sign up×
Community /Pin to ProfileBookmark

How to remove white spaces?

Hi,
how do you remove white space? I have tried the following but with no success:

[CODE]
var a = “he ll o o”;

function bla(){
if(a.match(/(s)/))alert(“Ok”); //works

a.replace(/(s)/,””); //does not work
}
[/CODE]

any help appreciated!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooJan 06.2012 — use the g flag to remove all matches:
[CODE]
function stripspaces(what){
return what.replace(/s+/g,'');
}
alert(stripspaces("he ll o o"));[/CODE]
Copy linkTweet thisAlerts:
@xelawhoJan 06.2012 — you have to redefine the string and also use the g modifier to make sure all white spaces are replaced:

[CODE]
var a = "he ll o o";

a=a.replace(/(s)/g,"")
alert(a)
[/CODE]
Copy linkTweet thisAlerts:
@Laurence485authorJan 07.2012 — thanks for your answers, i was able to get it to work using the g modifier.
×

Success!

Help @Laurence485 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...