/    Sign up×
Community /Pin to ProfileBookmark

Using var.replace("foo") when no break spaces are present.

I may have the solution but advice still needed.

I have grabbed all the links in an array and tried bubble sorting them alphabetically. The first two things I noticed was the “n” which I can eliminate but I use Firebug as my debugger and it reports whitespace as whitespace. I do use a lot of   ‘s in the HTML so it may be these that cause the results to show “undefined”. I tried removing “undefined” and got a null instead. I tried removing the null and got undefined.

As I am looking at the “.text” property and Firebug probably shows   as whitespace , maybe I should look for   and possibly use “.innerHTML” instead. All I need is to remove leading, trailing & multiple spaces.

What do the experts think? I am going home to try, but this is at the end of a very long road.

TIA

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 28.2010 — You may try Regular Expression to match and/or replace spaces:

http://lawrence.ecorp.net/inet/samples/regexp-intro.php
Copy linkTweet thisAlerts:
@MrRedauthorApr 28.2010 — Sorry - I show have said I use RegExp's eg:
<i>
</i>fred.replace(/n/g,/ /)
//and then
fred.replace(/ /,/ /)
//as many times as is necessary.

what I may try before migrating to innerHTML is

fred.replace(/&amp;nbsp;/,/ /)

or same for the innerHTML instead.

I did (stupidly) try to remove "" & "n" as it was literally as displayed before the penny dropped.
Copy linkTweet thisAlerts:
@KorApr 28.2010 — The single space RegExp meta character is [b]s[/b]. [b]n[/b] has no special meaning.
Copy linkTweet thisAlerts:
@MrRedauthorApr 29.2010 — After trying all manner of things I found IE & FF can cope with

.charCodeAt(forloopnum) and re-constructing the variable from before and after the offending character - 160 for &nbsp; ( can't use bracket here in the presence of colons!!!) :eek:

Trying to do this with character 13 made it all fall apart - it is the delimiter in arrays!!! but that was solved anyway with

.replace(/n/,/ /)

I did not have much joy with s or w.

Thanks for the advice.
×

Success!

Help @MrRed 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...