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 !

Inserting Unicode symbol

Postby michaelk on Sun Aug 22, 2021 11:44 pm

What is the best way to insert a Unicode symbol such as a musical flat sign (U+266D) into text produced by Dyalog APL?
michaelk
 
Posts: 28
Joined: Wed Feb 10, 2010 8:38 am

Re: Inserting Unicode symbol

Postby Morten|Dyalog on Mon Aug 23, 2021 8:07 am

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.
User avatar
Morten|Dyalog
 
Posts: 417
Joined: Tue Sep 09, 2008 3:52 pm

Re: Inserting Unicode symbol

Postby michaelk on Mon Aug 23, 2021 8:50 am

Thanks, Morten. Where is the [UCS] table that assigns 9837 to the flat symbol?
michaelk
 
Posts: 28
Joined: Wed Feb 10, 2010 8:38 am

Re: Inserting Unicode symbol

Postby Morten|Dyalog on Mon Aug 23, 2021 9:00 am

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
Morten|Dyalog
 
Posts: 417
Joined: Tue Sep 09, 2008 3:52 pm

Re: Inserting Unicode symbol

Postby Adam|Dyalog on Sun Aug 29, 2021 7:16 am

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'
User avatar
Adam|Dyalog
 
Posts: 98
Joined: Thu Jun 25, 2015 1:13 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest