Metoda JavaScript String fromCharCode () vrne niz, ustvarjen iz določenega zaporedja kodnih enot UTF-16.
Sintaksa fromCharCode()
metode je:
String.fromCharCode(num1,… , numN)
fromCharCode()
Način, da statično metodo, ki se imenuje z String
imenom razreda.
fromCharCode () Parametri
fromCharCode()
Metoda je v:
- num1,…, numN - zaporedje kodnih enot UTF-16 (številke med 0 in 65535 ). Številke, večje od 65535 (0xFFFF), so okrnjene.
Vrnjena vrednost iz fromCharCode ()
- Vrne niz dolžine N, sestavljen iz N določenih kodnih enot UTF-16.
Opomba : fromCharCode()
Metoda vrne niz in ne String
predmeta.
Primer: Uporaba metode fromCharCode ()
// most common characters can be represented by single 16 bit value let string1 = String.fromCharCode(65, 66, 67); console.log(string1); // ABC // numbers can be passed as a hexadecimal value let string2 = String.fromCharCode(0x2014); console.log(string2); // - // num> 65535 are truncated, so here 1 is truncated // equivalent to 0x2014 let string3 = String.fromCharCode(0x12014); console.log(string3); // -
Izhod
ABC - -
Vendar dodatni znaki v UTF-16 zahtevajo dve kodni enoti.
String.fromCharCode(0xD83C, 0xDF03); // Code Point U+1F303 "Night with String.fromCharCode(55356, 57091); // Stars" == "uD83CuDF03"
Če si želite ogledati celotno tabelo UTF-16, obiščite tabelo ASCII.
Priporočeno branje:
- String JavaScript charCodeAt ()