Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22631 > unrolled thread
| Started by | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| First post | 2014-01-15 15:23 -0700 |
| Last post | 2014-01-16 13:37 -0700 |
| Articles | 14 — 5 participants |
Back to article view | Back to comp.lang.javascript
Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-15 15:23 -0700
Re: Removing ' ' from strings ?? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-15 23:35 +0100
Re: Removing ' ' from strings ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-15 23:44 +0000
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-15 17:07 -0700
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 09:08 -0700
Re: Removing ' ' from strings ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-16 16:18 +0000
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 10:23 -0700
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 10:35 -0700
Re: Removing ' ' from strings ?? Martin Honnen <mahotrash@yahoo.de> - 2014-01-16 18:58 +0100
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 11:05 -0700
Re: Removing ' ' from strings ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-16 18:01 +0000
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 11:10 -0700
Re: Removing ' ' from strings ?? Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-16 19:17 +0000
Re: Removing ' ' from strings ?? "Mel Smith" <med_cutout_syntel@aol.com> - 2014-01-16 13:37 -0700
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-15 15:23 -0700 |
| Subject | Removing ' ' from strings ?? |
| Message-ID | <bjog40Fe7h5U1@mid.individual.net> |
Hi:
I'm probably having a senior moment, but with IE8 as a test bed, I
cannot seem to replace ' ' with an ordinary space character.
e.g.,
Let's say my input text string is:
var mytext = " " + "Hello" + " " + "World" +
" "
Using IE8:
var newtext = mytext.replace(" "," ") ;
The above statement*works* in Chrome (i.e., it replaces ' ' with an
'ordinary' space character
But, in IE8 , these ' ' sequences are *not* replaced -- just
ignored ??
I need a 'kick-in-the-butt' please -- perhaps a real regex string that would
work in all cases ?
Thank you.
-Mel Smith
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-01-15 23:35 +0100 |
| Message-ID | <XnsA2B6F00B7DFE3eejj99@194.109.133.133> |
| In reply to | #22631 |
"Mel Smith" <med_cutout_syntel@aol.com> wrote on 15 jan 2014 in
comp.lang.javascript:
> Hi:
>
> I'm probably having a senior moment, but with IE8 as a test bed, I
> cannot seem to replace ' ' with an ordinary space character.
>
> e.g.,
>
> Let's say my input text string is:
>
> var mytext = " " + "Hello" + " " + "World" +
> " "
>
> Using IE8:
>
> var newtext = mytext.replace(" "," ") ;
>
> The above statement*works* in Chrome (i.e., it replaces ' '
> with an 'ordinary' space character
No, only the first one.
>
> But, in IE8 , these ' ' sequences are *not* replaced -- just
> ignored ??
IE11 does the same as chrome, are you sure about IE8?
> I need a 'kick-in-the-butt' please -- perhaps a real regex string that
> would work in all cases ?
Better always use regex with replace(),
and use the global switch if necessary:
var newtext = mytext.replace(/ /g,' ') ;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-01-15 23:44 +0000 |
| Message-ID | <0.14085b2fab6b953fb903.20140115234423GMT.87bnzcolns.fsf@bsb.me.uk> |
| In reply to | #22633 |
"Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
> "Mel Smith" <med_cutout_syntel@aol.com> wrote on 15 jan 2014 in
> comp.lang.javascript:
<snip>
>> Let's say my input text string is:
>>
>> var mytext = " " + "Hello" + " " + "World" +
>> " "
>>
>> Using IE8:
>>
>> var newtext = mytext.replace(" "," ") ;
>>
>> The above statement*works* in Chrome (i.e., it replaces ' '
>> with an 'ordinary' space character
>
> No, only the first one.
>
>>
>> But, in IE8 , these ' ' sequences are *not* replaced -- just
>> ignored ??
>
> IE11 does the same as chrome, are you sure about IE8?
On my IE8 VM, the code works as expected.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-15 17:07 -0700 |
| Message-ID | <bjom61FfeukU1@mid.individual.net> |
| In reply to | #22635 |
> On my IE8 VM, the code works as expected.
>
> <snip>
> --
> Ben.
Ben & Evertjan:
I'll go back to my 'real' code and take another look. I probably (as
usual) did something wrong --- *but* Chrome worked perfectly ??
Thanks,
-Mel
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 09:08 -0700 |
| Message-ID | <bjqegcFqgpcU1@mid.individual.net> |
| In reply to | #22637 |
Hi All:
My IE8 still won't change the nbsp; coding to spaces altho Chrome does
so.
Below is my actual latest test code
and here is the definition of my alltrim() function
function alltrim(str) {
return str.replace(/^\s+|\s+$/g,"") ;
}
Thanks
-Mel Smith
********* latest test code *************
option = el.options[nindex] ; // text string with multiple 'nbsp;' in it
textstr = option.text ;
textstr = textstr.replace(/nbsp;/g," ") ; // change nbsp; into space
globally
// get the clubname first
npos1 = textstr.search("Tees") ;
clubname = textstr.substring(0,npos1) ;
alert("a. Code at start= " + clubname.charCodeAt(0)+" Code at end=
"+clubname.charCodeAt(clubname.length-1)) ;
clubname = alltrim(clubname) ; // trim spaces off of the ends of the
clubname
alert("b. Code at start= " + clubname.charCodeAt(0)+" Code at end=
"+clubname.charCodeAt(clubname.length-1)) ;
// in both alerts above the chars at the start and end are Unicode 160
(unbreakable space) for IE8
alert("clubname=**"+clubname+"** Len = "+clubname.length) ;
***********************************
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-01-16 16:18 +0000 |
| Message-ID | <0.ae3d2a008e8309f72c9a.20140116161844GMT.87ob3blx23.fsf@bsb.me.uk> |
| In reply to | #22638 |
"Mel Smith" <med_cutout_syntel@aol.com> writes:
> ********* latest test code *************
> option = el.options[nindex] ; // text string with multiple 'nbsp;' in it
> textstr = option.text ;
> textstr = textstr.replace(/nbsp;/g," ") ; // change nbsp; into space
> globally
"nbsp;" is not the same as " ".
> // get the clubname first
> npos1 = textstr.search("Tees") ;
> clubname = textstr.substring(0,npos1) ;
> alert("a. Code at start= " + clubname.charCodeAt(0)+" Code at end=
> "+clubname.charCodeAt(clubname.length-1)) ;
> clubname = alltrim(clubname) ; // trim spaces off of the ends of the
> clubname
> alert("b. Code at start= " + clubname.charCodeAt(0)+" Code at end=
> "+clubname.charCodeAt(clubname.length-1)) ;
> // in both alerts above the chars at the start and end are Unicode 160
> (unbreakable space) for IE8
>
> alert("clubname=**"+clubname+"** Len = "+clubname.length) ;
> ***********************************
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 10:23 -0700 |
| Message-ID | <bjqit9Frfe7U1@mid.individual.net> |
| In reply to | #22639 |
Ben said:
>
> "nbsp;" is not the same as " ".
Whoops !!!
I'll slow dow and try again :(
-Mel
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 10:35 -0700 |
| Message-ID | <bjqjjpFrkm6U1@mid.individual.net> |
| In reply to | #22640 |
Hi:
The corrected real code is below.
Unfortunately, the result id the same: is replaced by " " for
Chrome but *not* for IE8
********************
option = el.options[nindex] ; // text string with multiple 'nbsp;' in it
textstr = option.text ;
textstr = textstr.replace(/ /g," ") ; // change ' ' into space
globally
// get the clubname first
npos1 = textstr.search("Tees") ;
clubname = textstr.substring(0,npos1) ;
alert("a. Code at start= " + clubname.charCodeAt(0)+" Code at end=
"+clubname.charCodeAt(clubname.length-1)) ;
clubname = alltrim(clubname) ; // trim spaces off of the ends of the
clubname
alert("b. Code at start= " + clubname.charCodeAt(0)+" Code at end=
"+clubname.charCodeAt(clubname.length-1)) ;
// in both alerts above the chars at the start and end are Unicode 160
(unbreakable space) in IE8
alert("clubname=**"+clubname+"** Len = "+clubname.length) ;
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2014-01-16 18:58 +0100 |
| Message-ID | <52d81dca$0$6547$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #22641 |
Mel Smith wrote: > Unfortunately, the result id the same: is replaced by " " for > Chrome but *not* for IE8 > > > ******************** > option = el.options[nindex] ; // text string with multiple 'nbsp;' in it > textstr = option.text ; > textstr = textstr.replace(/ /g," ") ; // change ' ' into space > globally Is that script code you have inline inside of an HTML document? Or why do you use an HTML entity reference? Have you tried textstr.replace(/\u00A0/g, ' ') ?
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 11:05 -0700 |
| Message-ID | <bjqlcdFs117U1@mid.individual.net> |
| In reply to | #22642 |
Martin said:
> Is that script code you have inline inside of an HTML document? Or why do
> you use an HTML entity reference?
Yes, it is in a javascript function in an html doc that is getting the
text string from a option of a <select> tag -- but maybe I don't undestand
what you're asking ??
> Have you tried
> textstr.replace(/\u00A0/g, ' ')
> ?
No, but I'll give it a try.
Thanks Martin.
-Mel
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-01-16 18:01 +0000 |
| Message-ID | <0.ee4c585b3346833f2edb.20140116180123GMT.87ppnrkdqk.fsf@bsb.me.uk> |
| In reply to | #22641 |
"Mel Smith" <med_cutout_syntel@aol.com> writes:
> The corrected real code is below.
>
> Unfortunately, the result id the same: is replaced by " " for
> Chrome but *not* for IE8
>
>
> ********************
> option = el.options[nindex] ; // text string with multiple 'nbsp;' in it
> textstr = option.text ;
> textstr = textstr.replace(/ /g," ") ; // change ' ' into space
> globally
>
> // get the clubname first
> npos1 = textstr.search("Tees") ;
> clubname = textstr.substring(0,npos1) ;
> alert("a. Code at start= " + clubname.charCodeAt(0)+" Code at end=
> "+clubname.charCodeAt(clubname.length-1)) ;
> clubname = alltrim(clubname) ; // trim spaces off of the ends of the
> clubname
> alert("b. Code at start= " + clubname.charCodeAt(0)+" Code at end=
> "+clubname.charCodeAt(clubname.length-1)) ;
> // in both alerts above the chars at the start and end are Unicode 160
> (unbreakable space) in IE8
Then the replace won't work. / / does not match U+00A0 (160
decimal), it matches an ampersand followed by an 'n' etc. You can
replace both by writing:
textstr.replace(/ |\u00a0/g," ")
> alert("clubname=**"+clubname+"** Len = "+clubname.length) ;
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 11:10 -0700 |
| Message-ID | <bjqlkhFs2qgU1@mid.individual.net> |
| In reply to | #22643 |
Hi Ben:
In just tried your /\u00A0/g code and it works perfectly.
Thanks !
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-01-16 19:17 +0000 |
| Message-ID | <lb9b7c$7p1$1@dont-email.me> |
| In reply to | #22641 |
On Thu, 16 Jan 2014 10:35:48 -0700, Mel Smith wrote: > textstr = option.text ; option.text may not be the same as option.innerHTML, especially if the html contains entity codes. I suspect the issue is that the html entity codes have been translated into some other encoding scheme (ie other than html entity encoding) in the text string that you're getting back as the value of option.text. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2014-01-16 13:37 -0700 |
| Message-ID | <bjqu8rFtvtnU1@mid.individual.net> |
| In reply to | #22646 |
Denis said:
>> textstr = option.text ;
>
> option.text may not be the same as option.innerHTML, especially if the
> html contains entity codes. I suspect the issue is that the html entity
> codes have been translated into some other encoding scheme (ie other than
> html entity encoding) in the text string that you're getting back as the
> value of option.text.
Hi Denis:
I ave simple text (with the inclusion of codes, and MArtin's
solution resolves everything nicely. IE* and Chrome react exactly the same.
I tried 'innerHTML' for a few minutes, and came up with the long string
of chars interspersed with
So, back to Martin's solution.
Thanks to all !
-Mel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web