1

I would like to show a small italic i (math symbol) in Kotlin using Android Studio. I see it has a value in Unicode-32, but that is not the character set that is the base for Kotlin in Android. Based on what I can determine, the base unicode is UTF-16 (hex), since that is what I used to define the other unicode characters I use. See https://unicode-table.com/en/.

For example, I use \u221A for the square root sign. However, there is apparently no small italic i in the same character set. Is there a way to generate the small italic i using Unicode 32 without having to redefine all the other unicode characters I use? Thanks in advance for your help.

Earl Whitney
  • 103
  • 1
  • 9
  • Unicode characters outside of the BMP can be encoded using surrogate pairs.See https://stackoverflow.com/questions/5903008/what-is-a-surrogate-pair-in-java – Henry Aug 20 '18 at 03:29

1 Answers1

2

Strings in Kotlin (and Java) are specified in 16-bit characters, therefore you can't include a 32-bit Unicode character inside a string literal.

You can, however, break your character into two 16-bit code points called a surrogate pair, like so: \uD835\uDC56

Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47
  • Thank you for that. I have been both experimenting and looking for some code to accomplish the combining of surrogate pairs and have been unsuccessful. Can you make any suggestions of code? My understanding is that the character I want has surrogate pairs {\uD835, \uDCBE'}. Thank you. – Earl Whitney Aug 21 '18 at 15:56
  • @EarlWhitney I gave the precise surrogate pair in my answer. What is the difficulty in using it in your code? Have you tried using it in a simple string literal? i.e. `String smallItalicI = "\uD835\uDC56"` ? – Dmitry Brant Aug 21 '18 at 17:16
  • You are right. The i that shows is very small and blends into the square root sign that follows it, so I could not see that it was working. Upon closer inspection, I see it now. Thank you for your help! – Earl Whitney Aug 21 '18 at 18:25