Unicode symbol not rendering in Push Notification

195 Views Asked by At

I have a number of string literals in my C# that include unicode characters. We are using these to send Push Notifications via Azure Notifcations Hub.

When I send one of the strings in this first set below the notification renders with the expected text and emoticon.

  • "\u26a1 Hello! \u26a1", "Hello world."
  • "Ready to record? \ud83d\udce3", "Let’s do this!"
  • "\ud83d\udc40 Got anything ?", "We’d love to hear from you."

Any of the ones in the set below do appear as Push Notifcations but the special symbols, green circle, amber circle and red circle do not. I'll try and grab a screen shot and reedit this

  • "Signal Update", "Signal turned Red. \u1F534 Tap for more." "Signal
  • "Update", "Signal is Green. \u1f7e2 Tap for more." "Signal Active",
  • "Signal is Green. \u1f7e2 Tap for more."

I notice that VS 2022 does not fully highlight the escaped unicode strings that do not work and they all have an escape sequence length greater than 5 chars but that fact is likely a red herring. Here is the VS2022 rendering

enter image description here

Note the text "...Amber, \u1f7e1 Tap for more". This is how that is rendered in a Push Notification

enter image description here

Note the "1" after the supposed symbol

1

There are 1 best solutions below

0
Pat Long - Munkii Yebee On

The reason that my unicode characters were not displaying correctly was that I was not escaping them properly in the C# string literal.

26A1 is an example of the strings that were displaying correctly. This string is from the UTF16 range and can be escaped with the escape sequence starting "\u", note the lower case "u".

1F7E2 is an example of the strings that were not displaying correctly. I naively copied the earlier escape sequence and just changed the characters to be escaped. However this unicode string is from the UTF32 range and needs a different escape sequence, the uppercase u, "\U" making the string literal "Signal is Green. \U0001F7E2 Tap for more." Note the leading zeroes too.

References that I found useful were