Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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)?
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
thank u Jong and John.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
String.fromCharCode(parseInt(uni,16));
Find more inspiration, events, and resources on the new Adobe Community
Explore Now