Computing.Net > Forums > Programming > Javascript - decimal array to ASCII

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Javascript - decimal array to ASCII

Reply to Message Icon

Name: Infinite Recursion
Date: March 30, 2004 at 12:49:50 Pacific
OS: na
CPU/Ram: na
Comment:

I have a javascript that contains an array...
var myArr = new Array(10);

This array hold decimal values of characters that I need to assign to another variable, a string.

How do I get the variables from integers(?) to characters while still being able to assign them into an array?

Thanks!

Sara



Sponsored Link
Ads by Google

Response Number 1
Name: Rolos
Date: March 30, 2004 at 15:37:19 Pacific
Reply:

Hi Sara,

You can use parseFloat(myArray[n]); to convert a string to a decimal. Javascript treats the intial value assigned to the variable as a string, if I am not mistakened. So you can just reassign values of variables (since they are already treated as strings) to other variables with no problem.

You can observe this behavior if you try and do the following.

var myArray = new Array(4);
myArray[0] = "Hi";
myArray[1] = "21.222222";
myArray[2] = "21";
// variable declarations.

document.writeln(myArray[0] + "<br/>");
document.writeln(myArray[1] + myArray[2] + "<br/>");
document.writeln(parseFloat(myArray[1]) + parseFloat(myArray[2]) + "<br/><br/>");
// example of concatenation and actual addition.
// you can use parseInt() instead of parseFloat().

document.writeln("myArray[0] before: " + myArray[0] + "<br/>");
document.writeln("myArray[1] before: " + myArray[1] + "<br/><br/>");
// initial variable assignment values.

myArray[0] = myArray[1];
myArray[1] = myArray[2];
// variable value reassignment.

document.writeln("myArray[0] after: " + myArray[0] + "<br/>");
document.writeln("myArray[1] after: " + myArray[1] + "<br/>");
// new values after value reassignment.

Of course, you can also use parseInt() to truncate decimal values or convert any kind of string to an integer value. Did this answer your question?

- Rolos



0

Response Number 2
Name: Don Arnett
Date: March 30, 2004 at 15:40:22 Pacific
Reply:

I took her question to mean that the array holds decimal values (ASCII codes) for individual characters.


0

Response Number 3
Name: Infinite Recursion
Date: March 30, 2004 at 18:07:36 Pacific
Reply:

Thanks for the responses and comments.

Don is right, I am trying to get decimal values into their character equivalents to form a string that can be assigned to a variable later in the code.

Thanks.

Sara


0

Response Number 4
Name: Rolos
Date: March 31, 2004 at 01:20:38 Pacific
Reply:

My apologies.

- Rolos


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Javascript - decimal array to ASCII

Javascript Menu - Call to PL/SQL www.computing.net/answers/programming/javascript-menu-call-to-plsql/9915.html

Hex to ascii program www.computing.net/answers/programming/hex-to-ascii-program/1960.html

Java need code: hex to Ascii www.computing.net/answers/programming/java-need-code-hex-to-ascii/3727.html