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
29
votes
8 answers

Can I pass an array into fromCharCode

I might be asking the wrong question here, so I apologize if the answer is on another thread... but I've looked around to no avail. in a snippet, why doesn't this work? array = [72,69,76,76,79]; document.write(String.fromCharCode(array)); I'm…
Nick Briz
  • 1,917
  • 3
  • 20
  • 34
22
votes
2 answers

Javascript String.fromCharCode Case Sensitivity?

I am simply listening for a keyup event of an input element and gather the results into a string like so word=word+String.fromCharCode(key.keyCode); The problem is that the word is in capital letters while I want it to be case-sensitive. For…
Joel Blum
  • 7,750
  • 10
  • 41
  • 60
11
votes
6 answers

How can I check the new value of a text field on keypress?

I have a single form field and I need to be able to detect when the field changes and execute some additional code using the new value of the field. I only want to execute the code if the key pushed actually changes the value of the text box. Here's…
Stephen Sorensen
  • 11,455
  • 13
  • 33
  • 46
8
votes
4 answers

string.replace(fromCharCode() , '') cannot replace characters

When I parse the XML, it contains abnormal hex characters. So I tried to replace it with empty space. But it doesn't work at all. Original character : � hex code : (253, 255) code : xmlData = String.replace(String.fromCharCode(253,255),"…
user1127017
  • 91
  • 1
  • 2
  • 3
7
votes
1 answer

charCodeAt and fromCharCode do not return the same character

In theory, no matter what the input is, the output should be unchanged: String.fromCharCode("a".charCodeAt(0)); //"a" This makes sense because I'm just trying to get the char code of a character, and then casting it back to a character. However…
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
6
votes
2 answers

What is the PHP equivlent of fromCharCode?

Is there a PHP function that takes an integer and return the Unicode character of that number?
qwertymk
  • 34,200
  • 28
  • 121
  • 184
5
votes
2 answers

array join function not working

for some reason Im not able to see why my array join method wont work. here's the quick code for review: function rot13(str) { // LBH QVQ VG! var strAry = str.split(''); var transformed = strAry.map(function(val){ if(val === " ") return "…
Jarg7
  • 1,588
  • 2
  • 13
  • 23
4
votes
1 answer

How get real char code from an emoji in JavaScript?

I have, for example, this emoji: ... and i want to get your char code. i tried this: var emoji = "" var char_code = emoji.charCodeAt() console.log(emoji,char_code) But when using String's fromCharCode method, I don't get the original…
ArtEze
  • 186
  • 1
  • 5
  • 17
4
votes
3 answers

VBScript chr() appears to return wrong value

I'm trying to convert a character code to a character with chr(), but VBScript isn't giving me the value I expect. According to VBScript, character code 199 is: � However, when using something like Javascript's String.fromCharCode, 199 is: Ç The…
David Brown
  • 35,411
  • 11
  • 83
  • 132
3
votes
1 answer

How do you convert a Javascript keyCode to a charCode?

In a Javascript keyboard event, a code is given for the key pressed, however, it is not an ASCII or UTF-8 character code, rather, it is a code for the keyboard key. Sometimes the keyCodes happen to match up with ASCII/UTF-8 codes, sometimes they do…
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
3
votes
1 answer

Javascript fromCharCode equivalent in C#

I have a function i Javascript which looks like the following // Use this to convert "0123DEF01234" (hex string) to // binary data based on 0x01 0x23 0xDE 0xF0 0x12 0x34 hex = "0123456789ABCDEFFEDCBA98765432100123456789ABCDEF"; hex =…
user7067778
3
votes
1 answer

Javascript .which .fromCharCode letter equivalents of charcodes for special characters

I'm learning object oriented javascript. As i'm passionate of typography, I'm making an OO js simple HTML type editor that listen to the "duration" of a pressed key in order to modify the weight of each letter with a specific varation of the…
gastngouron
  • 461
  • 1
  • 5
  • 15
3
votes
3 answers

String.charCodeAt Max Length

Take this code: var charCode = unkownVariable.charCodeAt(0); What is the max length that charCode can be? All my tests turned out as 2 character (2 digits). Will it ever be longer?
Nathan J.B.
  • 10,215
  • 3
  • 33
  • 41
3
votes
2 answers

Counterpart to Python's chr() in JavaScript

The JavaScript method String.fromCharCode() behaves equivalently to Python's unichar() in the following sense: print unichr(213) # prints Õ on the console console.log(String.fromCharCode(213)); // prints Õ on the console as well For my purposes,…
chessweb
  • 4,613
  • 5
  • 27
  • 32
2
votes
1 answer

javascript convert to turkish character fromCharCode

I print the value entered from the keyboard to the screen. but Turkish characters are written to the screen in a distorted way. How can I print Turkish characters properly? my javascript codes: window.addEventListener('keyup',function(event){ …
1
2 3 4 5