[Javascript] Replace Characters
Tim Lewis
twlewis at softhome.net
Wed May 16 10:14:47 CDT 2007
I have a file with carriage returns(ASCII 13) only, and I need to replace
these with carriage return and line feed(ASCII 13 and 10).
My code was not work, so I created a simple test using the
String.fromCharCode and replace. It is not working either. I have
included the simple code below. The idea in the code is to replace the d
in dog with an l. It appears that the replace function does not recognize
an ASCII value. Is there a way to make the replace function use an ASCII
value?
<html>
<head>
<script type="text/javascript">
<!--
function Main()
{
msg=confirm("Main routine!"); if (msg==false) {return;};
var sLineIn="dog";
var sLineOut="";
var chr100=String.fromCharCode(100); //character d
var chr108=String.fromCharCode(108); //character l
var msg=confirm("sLineIn is:" + sLineIn); if (msg==false) {return;};
sLineOut = sLineIn.replace(/chr100/g,chr108);
var msg=confirm("sLineOut is:" + sLineOut); if (msg==false) {return;};
}
-->
</script>
</head><body>
<form>
<input type="button" value="Click me!" onclick="Main()">
</form>
</body>
</html>
More information about the Javascript
mailing list