Inserting Unicode symbol

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
Post Reply
michaelk
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Inserting Unicode symbol

Post by michaelk »

What is the best way to insert a Unicode symbol such as a musical flat sign (U+266D) into text produced by Dyalog APL?
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Inserting Unicode symbol

Post by Morten|Dyalog »

You can use the function ⎕UCS to generate Unicode characters from code points, in this case that would be (⎕UCS 9837). Depending on your environment, you may simply be able to cut and paste the symbol into character constants, '♭' displays fine for me under Windows.
michaelk
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Inserting Unicode symbol

Post by michaelk »

Thanks, Morten. Where is the [UCS] table that assigns 9837 to the flat symbol?
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Inserting Unicode symbol

Post by Morten|Dyalog »

9837 is the decimal equivalent of 266D that you had found yourself. There is a user command to do conversions, if you don't have a hex calculator handy:

Code: Select all

      ]fromhex 266D
9837
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Inserting Unicode symbol

Post by Adam|Dyalog »

You can also use any 4-digit hexadecimal code (0000–FFFF) directly via the ⎕JSON system function:
      ⎕JSON'"\u266D"' ⍝ note the inner "double-quotes"

For added convenience, and to handle less than 4 digits, we can define:
      U←{0 ⎕JSON 1⌽'""\u',¯4↑'000',⍕⍵}
U'266D'
Post Reply