473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Conversion to ascii

<script type="text/javascript">
<!--
var alphabet = new Array();

function listAlphabet()
{
var j;

for(var i=0, j=65; i<=25; i++)
alphabet[i] = toascii(j++);

for(i=0; i<=25; i++)
document.write(alphabet[i]+" ");
}

listAlphabet();
alphabet = null;
//-->
</script>

The above doesn't work <sigh>.

I googled for something to convert integers to ascii in JS and
could find only the toascii() function above (and ToAscii() from
msdn developers' pages) which must be for C/C++ or Java -
or summat.

Shorely it can be done in JS?

--
altheim
May 21 '06 #1
4 6955
VK

altheim wrote:
<script type="text/javascript">
<!--
var alphabet = new Array();

function listAlphabet()
{
var j;

for(var i=0, j=65; i<=25; i++)
alphabet[i] = toascii(j++);

for(i=0; i<=25; i++)
document.write(alphabet[i]+" ");
}

listAlphabet();
alphabet = null;
//-->
</script>

The above doesn't work <sigh>.

I googled for something to convert integers to ascii in JS and
could find only the toascii() function above (and ToAscii() from
msdn developers' pages) which must be for C/C++ or Java -
or summat.


Yes, you must be got it from a wrong place, because JavaScript/JScript
doesn't have toascii() build-in function. But what is even more
important: JavaScript/JScript doesn't operate with ASCII - it's an
Unicode based language and it works with Unicode values.

You want to use String.fromCharCode method. Try this:
....
alert(String.fromCharCode(112, 108, 97, 105, 110));
....
(will alert the word "plain")

Unicode tables (charts) are on the regular place:
<http://www.unicode.org/charts/>

May 21 '06 #2

"VK" <sc**********@yahoo.com> wrote:
altheim wrote:
<script type="text/javascript">
<!--
var alphabet = new Array();

function listAlphabet()
{
var j;

for(var i=0, j=65; i<=25; i++)
alphabet[i] = toascii(j++);

for(i=0; i<=25; i++)
document.write(alphabet[i]+" ");
}

listAlphabet();
alphabet = null;
//-->
</script>

The above doesn't work <sigh>.

I googled for something to convert integers to ascii in JS and
could find only the toascii() function above (and ToAscii() from
msdn developers' pages) which must be for C/C++ or Java -
or summat.
Yes, you must be got it from a wrong place, because JavaScript/JScript
doesn't have toascii() build-in function. But what is even more
important: JavaScript/JScript doesn't operate with ASCII - it's an
Unicode based language and it works with Unicode values.

Yes, I'm afraid I am a little behind the times. I'm trying to move
on to JavaScript but finding it enormously difficult with not knowing
what functions are available.
You want to use String.fromCharCode method. Try this:
...
alert(String.fromCharCode(112, 108, 97, 105, 110));
...
(will alert the word "plain")
Thanks. This worked as expected.
Unicode tables (charts) are on the regular place:
<http://www.unicode.org/charts/>


--
altheim
May 21 '06 #3
VK
altheim wrote:
I'm trying to move
on to JavaScript but finding it enormously difficult with not knowing
what functions are available.


So why to starve yourselve? :-)

JScript 5.6
<http://msdn.microsoft.com/library/en-us/script56/html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp>

or

JavaScript 1.5
<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference>

(JScript and JavaScript are not two different languages to learn: that
is pretty much the same language with some subtle implementation
differences and some extra features in either version. The core can be
learn by either manual, but IMHO JScript docs are more "startup
friendly" - this is once again IMHO)

May 21 '06 #4
VK wrote:
[...] JavaScript/JScript doesn't operate with ASCII - it's an
Unicode based language and it works with Unicode values.


Nowadays, yes. Unicode support was not introduced before JavaScript 1.3
and JScript 3.0.
PointedEars
--
A man who works with his hands is a laborer; a man who works with his
hands and his brain is a craftsman; but a man who works with his hands
and his brain and his heart is an artist.
-- Louis Nizer, lawyer (1902-1994)
May 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
22
by: Martin Trautmann | last post by:
Hi all, is there any kind of 'hiconv' or other (unix-like) conversion tool that would convert UTF-8 to HTML (ISO-Latin-1 and Unicode)? The database output is UTF-8 or UTF-16 only - Thus almost...
6
by: KA Kueh | last post by:
Dear all, I have a requirement to replace the ' character with ASCII character (146) in C# but it seems that when I do the following the conversion is lost. char t = Convert.ToChar(146);...
8
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I...
15
by: Peter Afonin | last post by:
Hello, I'm struggling with the string conversion to MD5 which I've never user before. I have a string that I need to encode which looks approximately like this: ...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
5
by: Jamie Risk | last post by:
This is the code snippet that I've come up to convert a byte to string. Is there a best practiced method for such a conversion? - Jamie public static string ByteArrayToString(byte array) {...
2
by: DaveP | last post by:
hi i want to convert say letter A to its Ascii Value and back to its Character Value.. im cant Seem To Find how to do this Tks DaveP
4
by: vcnewbie | last post by:
Hi I'm maintaining a VisualC++ project to increase its security regarding stored passwords. I thought about using SHA256Managed to create a hash for the password when creating a user and when...
12
by: fermineutron | last post by:
I am trying to write a function which will convert a large ascii number, say 100 ascii digits, to its binary representation. It seems that evey algorithm I am trying to think of is backwards. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.