Click to See Complete Forum and Search --> : script help


qwas
10-04-2003, 11:28 AM
I'm making a web page which takes some data from a xml file containig national characters and i need a script which will change characters from xml's egz.:
"%B9" into my national character "¹"! I;ll be very greatefull for it!!

lillu
10-04-2003, 01:13 PM
Try the unescape("%B9"); method to convert a string from URL-encoded form.

Jona
10-04-2003, 02:52 PM
Assuming that these characters are string encoded, try this script:

http://geocities.com/god_loves_07/encode_decode.html


[J]ona

qwas
10-04-2003, 05:02 PM
thanks for help! i had never used js in making a html i'd rater use a script attached to html code! i don't know but maybe there is a command like replace or something luke this, i would be very greatefull for getting script which replaces for egz.: everey "a" from the source to "z" in the output file!

Jona
10-04-2003, 06:36 PM
<script type="text/javascript"><!--
var msg = "This is the text you want to change";
var chars = new Array("a","b","c"); // letters that will be replaced
var rep = new Array("x","y","z"); // letters that will replace the other letters

for(i=0; i<chars.length; i++){
msg = msg.replace(chars[i],rep[i]);
}
//--></script>


[J]ona

qwas
10-05-2003, 08:14 AM
thanks for help, but i can not use it becouse the var msg is changing

Jona
10-05-2003, 09:45 PM
Originally posted by qwas
thanks for help, but i can not use it becouse the var msg is changing

I do not understand your problem, please explain.

[J]ona

qwas
10-06-2003, 01:17 AM
the xml file is generated randomly so i don't know what toput instead var msg = "This is the text you want to change"; schould i put ther xml tags or ...??

pyro
10-06-2003, 07:23 AM
First of all, Jona's script should probably look more like this, so it will match the characters globally (ie. all characters), rather than just the first one it finds:

<script type="text/javascript"><!--
var msg = "This is the text you want to change";
var chars = new Array("a","b","c"); // letters that will be replaced
var rep = new Array("x","y","z"); // letters that will replace the other letters

for(i=0; i<chars.length; i++) {
re = new RegExp(chars[i], "g");
msg = msg.replace(re,rep[i]);
}
//--></script>

Next, if you want to use an XML file, you're going to need to use something else to load it in. I'd suggest PHP, and if you go with that, there's no sence in using JavaScript at all -- just do the replacing in PHP.