Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-29-2012, 06:55 PM   PM User | #1
code-in-time
New Coder

 
Join Date: Mar 2012
Posts: 59
Thanks: 65
Thanked 0 Times in 0 Posts
code-in-time is an unknown quantity at this point
how do you replace a char in a string

Hi

How do you replace a char in a string?

eg var d = f.replace(char(160), "-");


Thanks
code-in-time is offline   Reply With Quote
Old 05-29-2012, 07:17 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Something like this:-

Code:
txt = txt.replace(/Ä/g,"-");
txt = txt.replace(/ä/g,"-");
txt = txt.replace(/Ë/g,"-");
txt = txt.replace(/ë/g,"-");
Or perhaps you mean:-

Code:
<script type = "text/javascript">

var tstr = "Hello Ältere World";
var bstr = '';

for (i=0; i<tstr.length; i++) {
if (tstr.charCodeAt(i)>127) {  // outside ASCII range
bstr += '-';  // change to a hyphen
} 
else {
bstr += tstr.charAt(i);
}
}
alert (bstr);


</script>
Quizmaster: In legend, the gryphon has the body of a lion and the head and wings of which bird?
Contestant: A goose
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 05-29-2012 at 07:57 PM..
Philip M is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:32 AM.


Advertisement
Log in to turn off these ads.