Questions tagged [fromcharcode]

String.fromCharCode() is a static method in JavaScript that returns a string based on the unicode number passed in. To use this tag, the question must be using JavaScript and one of the primary issues is regarding String.fromCharCode().

String.fromCharCode() accepts UTF-16 code units and converts them to the representative string.

String.fromCharCode(65) // returns A

The method can accept up to 65535 code units to return multiple characters.

String.fromCharCode(65, 66, 67) // returns ABC

If the method is called with no parameters, it outputs a zero-length string.

You can also pass parameters in hexadecimal notation.

String.fromCharCode(0x41) // returns A

If a number larger than 65535 (0xFFFF) is passed as a parameter it will be truncated. For example:

String.fromCharCode(65535) 

65535 (1111111111111111) is the maximum and will output . However,

String.fromCharCode(65536)

65536 (10000000000000000) is over the maximum 16 bits and so will get truncated to 0000000000000000 which will then output a zero-length string.

References

69 questions
-1
votes
2 answers

How can i convert signed int in to char in js?

I'm trying to pass a png file from my server (cpp) to a socket (js) by numbers (each number from -128 to 127 is a range of standard characters in cpp) but if I use the String.fromCharCode() method - this won't work Output from String.fromCharCode is…
-1
votes
1 answer

In JavaScript, how does join vs += on a string handle utf encodings differently?

What is the difference between the below two operations that accounts for the one with join resulting in "÷C " where the other with reduce results in "÷C"? 1 // returns "÷C " ["f7","43"].map(x=>'0x'+ x).map(String.fromCharCode).join(''); 2 //…
-1
votes
1 answer

Caeser Cipher JavaScript

I think I am close to figuring this out. Object is to take a string of "encrypted" characters and decipher them to actual words. Perhaps my code isn't very elegant right now, I'll get there, but I CAN get the beginning 'str = "SERR PBQR PNZC"' to…
Rsp8
  • 133
  • 1
  • 10
-1
votes
1 answer

How should I do to type lowercase letters and symbols by using keyCode?

I have the following codes. I'd like to control the move of the car Lamborghini by typing. The problem is: I could ONLY type uppercase letters and numbers. How should I do to type lowercase letters and symbols? /*Use the keyboard to control…
Hao
  • 59
  • 6
-1
votes
2 answers

Why String.fromCharCode() does not work with variable as parameter?

I noticed that String.fromCharCode() does not work with a variable as parameter. Here is some sample code: var x = atob('ODAsNjUsODMsODMsODcsNzksODIsNjgsOTUsNDgsNDk='); console.log('\''+x.replace(new RegExp(',', 'g'),…
iHasCodeForU
  • 179
  • 11
-1
votes
2 answers

String.fromCharCode gives no result javaScript

after running code i get no result in window. and i cant find problem result have to be string created from charCode. function rot13(str) { var te = []; var i = 0; var a = 0; var newte = []; while (i < str.length) { te[i] =…
EdenLT
  • 15
  • 6
-1
votes
1 answer

Need to output image depending on what letter is typed into input box in javascript using fromCharCode, any ideas?

Okay so I'm working on a project where I have to output a cat image that resembles a letter in the alphabet depending on what letter the user types into the input box. So for example if a is typed in then a image of a cat that looks like an a will…
seanrs97
  • 323
  • 3
  • 14
-2
votes
1 answer

RegEx example for fromcharcode

This is a rudimentary question but what is the best regex expression to capture a fromcharcode range and making it efficient and extensible? To start off up to the number range, what is the best way to capture the number range section making it…
secure777
  • 1
  • 3
-5
votes
6 answers

What does this JavaScript code mean? "String.fromCharCode"

I found this code in an HTML file and I don't quite understand what it means. Does anyone have an idea? Thanks!