/    Sign up×
Community /Pin to ProfileBookmark

Replacing characters

I see that khalidali got angry at me because I was acting like if i was his boss . I’m sorry OK ? Well whatever . the script i found is on
[url]http://javascript.internet.com/forms/replace-characters.html[/url]
and i don’t know how to make it replace other charcters it just replaces “a” with “z” I would like that it would replace “a” with “y” , NO PROBLEM i just replace the “z” in the
out = “a”; // replace this
add = “z”; // with this
with “y” but how do I make it also replace other characters like “d” with “t” . I added another
out = “a”; // replace this
add = “z”; // with this
and it looked so
out = “a”; // replace this
add = “y”; // with this
out = “y”; // replace this
add = “o”; // with this
but now it only replaces y ? . I want that replces more then 1 character i want that every character will be replaced . Like this a with y , y with o , o with something else and so on . Every character schould have an other character that will replace it after you press the button . And could you please make a second text box so that after you press the button the replaced text will not appear in the same text box but in the second text box . OK and i’m sorry khalidali63 OK . But if you are still angry at me tthere will be no more “special thanks to khalidali63” if you are not khalidali then it’s you’re lucky day . UNDER THE SCRIPT I WILL PUT AN “SPECIAL THAKS TO SECTION AND YOU’RE NAME IS GOING TO BE THERE IF YOU WILL HELP . And for those who think i’m acting as if i were you’re boss listen i’m stupid i’m a worm . If you’re going to help me if i act like an idiot then i have no other choise but to ……. sing “I’m a little teapot …. . Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please Please
Help me

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@vickers_bitsFeb 07.2003 — i don't know what code you're using at the moment but maybe thi will help:
[CODE]
function findReplace(s,f,r){
//Replaces [f] with [r] within [s];
//eg: findReplace("helloworld","o","") returns "hellwrld";
var iMatch, sub1, sub2;
iMatch=0;
while(iMatch>=0){
iMatch=s.indexOf(f);
if(iMatch<0) return s;
sub1=s.substring(0,iMatch);
sub2=s.substring(iMatch+f.length,s.length);
s=sub1+r+sub2;
}
return(0);//NN4;
};
[/CODE]
Copy linkTweet thisAlerts:
@CharlesFeb 07.2003 — [font=monospace]<script type="text/javascript">

<!--

String.prototype.translate = function (c1, c2) {

var a1 = c1.split('');

var a2 = c2.split('');

var a = this.split('');

for (i=0; i<a.length; i++) {for (j=0; j<a1.length; j++) {if (a[i] == a1[j]) a[i] = a2[j]}}

return a.join('');

}



alert ('hello world'.translate('aeiou', 'AEIOU'));

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@CharlesFeb 07.2003 — [font=georgia]Oops, there's a wee bit of a problem with that one. Mayhaps this one will do:[/font]

[font=monospace]

<script type="text/javascript">

<!--

String.prototype.translate = function (s1, s2) {

var a1 = s1.split('');

var a2 = s2.split('');

var o = new Object();

for (i=0; i<a1.length; i++) {o[a1[i]] = a2[i]}

var a = this.split('');

for (i=0; i<a.length; i++) {if (o[a[i]]) a[i] = o[a[i]]};

return a.join('');

}



alert ('hello world'.translate('abcdefghijklmnopqrstuvwxyz', 'bcdefghijklmnopqrstuvwxyza'));

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@khalidali63Feb 07.2003 — [i]Originally posted by enigma [/i]

[B]

OK and i'm sorry khalidali63 OK . But if you are still angry at me tthere will be no more "special thanks to khalidali63" [/B]
[/QUOTE]
.

Thats all most of us really care that we have get "Thank yoo" so I will not miss a chance like that..:-)

Your question is not complete in the sense that you do no clearify which character should be replaced by which.

now I am writing this function,This is how it will work.In your previous post it was'nt clear that you want a random character be replaced or there is a specific list of characters that would replace any alphbetical characers.

Now here is the alphabet.Please respond that which character you want ot be replaced by what characers.

"abcdefghijklmnopqrstuvwxyz"

Saying sorry is corageous thing to do.And it actually shows some ones moral beliefs unlike some others in here who only believe to maliciously hurt others.

Anywasy respond to this I'll make sure your concerns are dealt with ,and I'dlove to see a "Special Thanks to Khalid" section

?

cheers

Khalid
Copy linkTweet thisAlerts:
@CharlesFeb 07.2003 — [font=georgia]Or you could simply use the second of my [font=monospace]translate[/font] methods posted above. You will notice that the method takes as parameters two expressions that are evaluated as strings. It returns the String with any characters in the first expression replaced with characters in the second expression. It's not as robust as Perl's transliteration operator but it works much the same way. (Actually, I've tried to give you an object oriented version of XPATH's [font=monospace]translate[/font] function. See http://saxon.sourceforge.net/saxon6.5.2/expressions.html#StringExpressions.)[/font]
×

Success!

Help @enigma 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.13,
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,
)...