0

I want to handle emoji for 3 points.

1- Represent Emoji: I have functionality where user enter in Entry(textbox) and I show it in Label. Currently I use Label control to display text. I want to show Emoji selected by user in Label. If I try to show that emoji in label, it shows ??. Do I need to set any property to represent symbol or I need to change control? If I need to change control, which control I should use.

2- Pass Emoji in API: I want to save user entered text. Currently I only save text to database using API. I want to save emoji but I don't know how to get encoded character of emoji. Please note that I will get saved text from API to display in label. So, I must be able to get it from API and represent it.

enter image description here Please suggest. Thank you

Nanji Mange
  • 2,155
  • 4
  • 29
  • 63
  • I wrote a blogpost on this topic sometime ago => https://smellyc0de.wordpress.com/2018/04/07/the-ultimate-guide-to-emojis/ – EvZ May 11 '18 at 12:13
  • @EvZ Thank you. Let me try it. – Nanji Mange May 11 '18 at 12:39
  • @EvZ I have tried and added screenshot in question. Actually I don't get encoded text from textbox. I have tried to check by text changed event of the textbox. Can you please suggest me if I need to change anything? – Nanji Mange May 16 '18 at 13:02

1 Answers1

0

1- Represent Emoji

This is an easy task - you don't have to do anything special as you can just do:

<Label x:Name="lbl" Text="{Binding Source={x:Reference Name=ent}, Path=Text" />
<Entry x:Name="ent" />

or

lb.Text = ent.Text;

emoji should appear correctly in the Label.

2- Pass Emoji in API

This can be tricky, it may break JSON deserialization and etc. But it all depends on your setup. Try to send it to the API and try to retrieve it back. If there will be some problems check the next threads to get a better idea:
how can I Deserialize emoji in json in C#
How do I remove emoji characters from a string?
and etc.

EvZ
  • 11,889
  • 4
  • 38
  • 76
  • Thanks. I got your point. Now issue is how do I get unicode characters for all the emojis in the string? I have separate post here:https://stackoverflow.com/questions/50385467/how-to-convert-emojis-from-to-unicode-in-xamarin-forms. If you have idea about it, can you please help me? – Nanji Mange May 17 '18 at 07:14
  • After some google, I have tried with following. `string res = BitConverter.ToString(Encoding.BigEndianUnicode.GetBytes(str)).Replace("-", "");` This is result is `res = D83DDE00`. I don't know above code is unicode or not. How can I convert back to original emoji or is there any other way to convert in unicode? Is there your project can help me for this? Please help – Nanji Mange May 17 '18 at 11:20
  • Maybe it will be easier just to encode the whole text to base64 before sending it to the API and decode before showing to user. Just a though. – EvZ May 17 '18 at 11:27