Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What is the dif? "\u2018" & "\u"+"2018"

Participant ,
Apr 01, 2010 Apr 01, 2010

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

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 01, 2010 Apr 01, 2010
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);

Translate
LEGEND ,
Apr 01, 2010 Apr 01, 2010

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)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2010 Apr 01, 2010
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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 01, 2010 Apr 01, 2010

thank u Jong and John.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 01, 2010 Apr 01, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2010 Apr 01, 2010

If your Javascript editor allows it

  • , you can also copy the quotes out of InDesign and paste them striaght into your string:
  • 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.

  • Surprise, surprise. The ESTK Editor does -- and that's not an April Fools' joke.
  • Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    LEGEND ,
    Apr 01, 2010 Apr 01, 2010
    LATEST

    String.fromCharCode(parseInt(uni,16));

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines