In article <ccfm4a$rcs$1@b agan.srce.hr>,
"Bad_Kid" <REMOVEzlocesto _dijete@yahoo.c o.uk> wrote:
[color=blue]
> how can I write text (chars) through numbers - (using ascii table)?? -
> whaat's the function that does conversion int-> char?[/color]
var i = 1;
alert(""+i);
In the case where you concatenate a string to a number, the result will
be a string.
alert(i);
In most instances, JavaScript will correctly convert a number from
integer to character as you expect.
Robert wrote:
[color=blue]
> In article <ccfm4a$rcs$1@b agan.srce.hr>,
> "Bad_Kid" <REMOVEzlocesto _dijete@yahoo.c o.uk> wrote:
>[color=green]
> > how can I write text (chars) through numbers - (using ascii table)?? -
> > whaat's the function that does conversion int-> char?[/color]
>
> var i = 1;
>
> alert(""+i);
>
> In the case where you concatenate a string to a number, the result will
> be a string.
>
> alert(i);
>
> In most instances, JavaScript will correctly convert a number from
> integer to character as you expect.
>
> Robert[/color]
I think what he means is he has int values between 65 and 90 inclusive (for
example), and wants to output the characters those integer values represent
in the "ascii" table.
To do that, he needs the static fromCharCode() method of the String object:
<script type="text/javascript">
for (var i = 65; i <= 90; i++) {
document.write( String.fromChar Code(i) + '<br>');
}
</script>
--
| Grant Wagner <gwagner@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
Bad_Kid wrote:[color=blue]
> how can I write text (chars) through numbers - (using ascii table)?? -
> whaat's the function that does conversion int-> char?[/color]
All numbers in ECMAScript and its implementations are double-precision
(64 bit) floating-point numbers. There are no real integers like in C
etc. and there is no "int" or "char" type ("char"s are strings of length
1). However, if you regard a floating-point number with a fractional
part of zero an integer value, then
String.fromChar Code(integer_va lue)
will use not only US-ASCII (7 bit) but also either ISO-8859-1 (8 bit),
the character encoding of the current locale or Unicode (UTF-16, 16
bit), depending on the implementation. Another way are string literals
where the same applies:
"\x20"
equals the space character (" ") and
"\u20AC"
equals the Euro sign as of Unicode.
This is a very basic question, please read the
guides and specs before you post next time.
The ECMAScript specifications are available at
<http://www.mozilla.org/js/language/>
JavaScript Guides and References are available at
<http://devedge.netscap e.com/central/javascript/>
The JScript Reference is available at
<http://msdn.microsoft. com/library/>
See the FAQ <http://jibbering.com/faq/> which is
posted here regularly.
Comment