Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  107] [ 6]  / answers: 1 / hits: 64330  / 15 Years ago, mon, march 15, 2010, 12:00:00

I want to create a string in JavaScript that contains all ascii characters. How can I do this?


More From » string

 Answers
15

My javascript is a bit rusty, but something like this:



s = '';
for( var i = 32; i <= 126; i++ )
{
s += String.fromCharCode( i );
}


Not sure if the range is correct though.



Edit:

Seems it should be 32 to 127 then. Adjusted.



Edit 2:

Since char 127 isn't a printable character either, we'll have to narrow it down to 32 <= c <= 126, in stead of 32 <= c <= 127.


[#97338] Thursday, March 11, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blair

Total Points: 384
Total Questions: 108
Total Answers: 86

Location: Northern Ireland
Member since Tue, May 5, 2020
4 Years ago
;