View Single Post
Old 02-21-2012, 06:28 PM   PM User | #1
lsd
New to the CF scene

 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lsd is an unknown quantity at this point
Help turning string of numbers into letters!

Hi, I'm very new to javascript, and I'm working on a simple script that will allow me to take a string of numbers, and convert it to a word. For example:

I type 00010203 into a box, and it would return abcd.

I've got the above to work, however..I'd like to add a couple special characters so that when the user types in a string that contains "32" it will return a ' ' (space). For example:

000102033200010203 would return 'abcd abcd'

Here's my code, as of now:

Code:
<script type="text/javascript">
function show_prompt()
{
	var s = prompt("Please enter a string of numbers");
	for (i = 0; i <=s.length; i = i+2)
{
var t = s.slice(i,i+2)
var n = parseInt(t,10) + 97
document.write (String.fromCharCode(n))
}
}

</script>
lsd is offline   Reply With Quote