0

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

Pat Long - Munkii Yebee
  • 3,592
  • 2
  • 34
  • 68
  • I've read your question several times, and I'm confused about what your problem actually **is**. What do "work" and "do not work" mean here? Are you seeing an error somewhere? Where do you see the error, and what do you do to trigger it? – canton7 Feb 01 '23 at 16:52
  • Please provide a *lot* more detail. No, there's nothing significant about a string literal of length 5 rather than 6. You've said very little about in what way the strings do or don't "work". – Jon Skeet Feb 01 '23 at 16:52
  • 4
    C# has two flavors of Unicode literals in strings, no more, no less: 4 digits or 8 digits. The 8-digit ones must use `\U`. `"Signal turned Red. \U0001F534 Tap for more."` will work. – Jeroen Mostert Feb 01 '23 at 16:53
  • 2
    @canton7 E.g. it will interpret `\u1F534` as `\u1F53` and `4`. – GSerg Feb 01 '23 at 16:53
  • [See here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/#string-escape-sequences) – canton7 Feb 01 '23 at 16:56
  • 2
    Right. I meant to say that it has *three* flavors of Unicode literals, no more, no less, as I forgot about `\x`.... :P For the long ones you still need `\U` though. – Jeroen Mostert Feb 01 '23 at 17:00
  • 2
    If by "string length" you really meant "escape sequence length" then the question would make a lot more sense. That's why it's so important that you put significant effort into making the question as clear as possible. – Jon Skeet Feb 01 '23 at 17:02
  • I've tightened up the question. I was being deliberately vague previously to catch as many opinions as possible. I appreciate people have better things to do than check my other questions but they are usually a lot better – Pat Long - Munkii Yebee Feb 01 '23 at 17:08
  • Thanks to @canton7 and Gserg for their comments and links. This is now working. I have edit question. When it is old enough I will add an answer. Thanks all and aplogies again for the initial question – Pat Long - Munkii Yebee Feb 01 '23 at 17:39

1 Answers1

1

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

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
Pat Long - Munkii Yebee
  • 3,592
  • 2
  • 34
  • 68