Copiar vínculo al Portapapeles
Copiado
Hi all
1) app.selection[0].insertionPoints[0].contents = "\u2018";
2) var uni = "2018";
app.selection[0].insertionPoints[0].contents = "\u"+uni;
why does the 2nd one is not working as expected? could anyone suggest on this?
thanks & regards
Ays.Hakkim
But at that point, why not use String.fromCharCode(2018)?
Because that will insert the Nko letter "Nya" (U+07E2). ![]()
Unicode codepoints are generally given in hexadecimal notation -- as in "\u2018" --, but the argument for fromCharCode is a number, defaulting to decimal. Either add the hexadecimal prefix "0x"
String.fromCharCode (0x2018);
or use the decimal value of this number
String.fromCharCode (8216);
Copiar vínculo al Portapapeles
Copiado
Because backslash escapes are interpreted by the JavaScript tokenizer at the time of input. So "\u" is inrepreted as an incomplete escape, and of course "2018" is a regular string.
I suppose you could probably use eval('"\u'+uni+'"') to construct the character. But at that point, why not use String.fromCharCode(2018)?
Copiar vínculo al Portapapeles
Copiado
But at that point, why not use String.fromCharCode(2018)?
Because that will insert the Nko letter "Nya" (U+07E2). ![]()
Unicode codepoints are generally given in hexadecimal notation -- as in "\u2018" --, but the argument for fromCharCode is a number, defaulting to decimal. Either add the hexadecimal prefix "0x"
String.fromCharCode (0x2018);
or use the decimal value of this number
String.fromCharCode (8216);
Copiar vínculo al Portapapeles
Copiado
thank u Jong and John.
Copiar vínculo al Portapapeles
Copiado
To complete the information provided above, if you need to create your Unicode character from a code given as a string (uni = "2018") you can use something like this:
String.fromCharCode(Number("0x" + uni))
Example:
var uni = "2018";
myInsertionPoint.contents = String.fromCharCode(Number("0x" + uni));
@+
Marc
Copiar vínculo al Portapapeles
Copiado
If your Javascript editor allows it
myInsertionPoint.contents = "“Hello”, he lied.";
A big font so you can see they're not the straight ones. Javascript doesn't care about what you literally put into the strings -- this and the "\u2018" notation both end up in memory exactly the same.
Copiar vínculo al Portapapeles
Copiado
String.fromCharCode(parseInt(uni,16));
Encuentra más inspiración, eventos y recursos en la nueva comunidad de Adobe
Explorar ahora