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
2
votes
2 answers

JavaScript Key Codes

I'm working with a JavaScript routine I didn't write. It is called from a text box's onkeydown attribute to prevent unwanted keystrokes. The first argument is apparently not used. The second argument is a list of characters that should be…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
2
votes
0 answers

JavaScript "String.fromCharCode" is returning a different set of characters than Python's "chr" function is

I am trying to run an encryption algorithm that takes an input message, breaks it up into blocks of four characters, moves "x" bits from the front to the back, and then converts it back into four scrambled characters. I believe that this is called a…
NightOwl
  • 21
  • 4
2
votes
1 answer

Why am I getting \u0000 instead of characters when using String.fromCharCode?

I could not find this particular problem addressed. The object is to decode a Caesar cipher. My code works to the point of putting the correct letter codes into an array. I can manually turn that array into the correct string like…
Kelcey Wilson
  • 69
  • 1
  • 9
2
votes
4 answers

Get string from a list contain Unicode in JavaScript

I have a list of Unicode values [65, 66, 67] and I want the corresponding string "ABC". I looked into the documentation and found the function String.fromCharCode()that does what I need to do. The only problem is that the arguments needs to be a…
Abhinav Srivastava
  • 840
  • 10
  • 17
2
votes
1 answer

Javascript String.fromCharCode() latin1 encoding issue

I don't know if I can write a fiddle for this so I'll just try to explain this as well as I possibly can. We have an application where we've written an editor. We need to check some grammar rules on strings/tokens that are being entered into the…
Byebye
  • 934
  • 7
  • 24
2
votes
3 answers

Block typing in any other alphabet than english

I know the JavaScript that restricts entering some special characters or number, etc using charcode and ascii value. Is there anyway that I can block people entering any other language (I mean alphabet) expect English? More specifically how can I…
Karthik Malla
  • 5,570
  • 12
  • 46
  • 89
2
votes
0 answers

javascript char code to WIN32 Virtual-Key Code

How to convert in javascript char code to WIN32 Virtual-Key Code? I mean "q" allways has 81 code, even if i will press it in russian keyboard for example. In wpf I can use this code, but I need something simular in javascript keyCodeValue =…
1
vote
2 answers

jQuery : event.which returns different codes when a number is pressed from numpad and when from the numbers keys above alphabets

When I press 8 from the numbers present above the alphabets on the keyboard, event.which returns 56, but when I press 8 from the numpad given at the side, it returns 104 (ascii of 'h'). I was doing this : var keyPressed =…
Daud
  • 7,429
  • 18
  • 68
  • 115
1
vote
1 answer

To make Golang rune to utf-8 result same as js string.fromCharCode

go var int32s = []int32{ 8, 253, 80, 56, 30, 220, 217, 42, 235, 33, 211, 23, 231, 216, 234, 26, } fmt.Println("word: ", string(int32s)) js let int32s = [8, 253, 80, 56, 30, 220, 217, 42, 235, 33, 211, 23, 231, 216, 234, 26] str =…
Tpircsnart
  • 47
  • 5
1
vote
2 answers

Add subscript to numbers on the fly as user types using jQuery

Is it possible to add a subscript tag to numbers as a user types into an textbox, for example if a user was to type in H20 it would instantly of converted to H20. I am looking for a solution using jQuery?
user786731
  • 161
  • 2
  • 4
  • 11
1
vote
1 answer

Unknown charcode inside text in Javascript causes IndexOf funtion to return -1

Below code enters the if clause below, var title = "İnsanlar"; var keyword = "in"; title = title.toLowerCase(); if(title.indexOf(keyword) == -1) { alert(title); } when I did some debugging, I realised that title.charCodeAt(1) returns 775 while…
HOY
  • 1,067
  • 10
  • 42
  • 85
1
vote
1 answer

Question about fromCharCode and ending an "if" statement

I'm working on a simple cipher algorithm and I'm trying to figure out how to stop the if statement at character 122 (z) and start back at char 97 (a) once the character count exceeds 122. This is what I have so far and have looked around on MDN and…
JackJack
  • 181
  • 1
  • 1
  • 20
1
vote
0 answers

Number pad (10 key) character codes incorrect in ie

I notice that when I listen for a keypress the character codes show up differently in Chrome and IE. Does anyone know why this is happing? Chrome: numpad key: 0, String.fromCharCode(48) => "0" numpad key: 1, String.fromCharCode(49) => "1" numpad…
jwerre
  • 9,179
  • 9
  • 60
  • 69
1
vote
4 answers

From binary to charcode to text javascript

i'm in the freecodecamp's bonfire "binary agents" and I almost got it. It returns the correct answer but with an "undefined" first and I don't see why.. function binaryAgent(str) { var arr = str.split(" "); var charcoded = []; var finalStr; for…
Chantun
  • 81
  • 1
  • 7
1
vote
3 answers

ROT13 Cipher code from .charCodeAt()?

I am new at javascript and this is the last course from Basic Algorithm Scripting.I am trying to understand this line of codes as I get on the next part of Front End Development Certificate from free code camp,I want to understand eveything.I've…