1

I'm working with emojis, and I choose to store: 😂 instead 😀 into the database, which works fine.

How can I reload the text in a asp:TextBox and convert 😂 into 😀 ?

In database: test 😀😁😂

In text field I need: test 😀😀😀 for edit purposes.

I think that a simple code resolve this issue like:

txtComment_Lmt.Text = Server.HtmlDecode("test 😀😁😂");

But this approach does not working, i known that emoji is related with unicode.

How can I convert emoji html entitity to something that work in edit mode on textbox?

4
  • but how did you get to `😂" ? what format is that. Can you show on your question how to got to that values. Perhaps it will show some leads. Commented Aug 14, 2020 at 20:44
  • I get this value on C# converting the emoji unicode to html entitie, but this is not my problem code lValue_Cmt += "&#" + char.ConvertToUtf32(pValue_Cmt, lIndex) + "; code Commented Aug 14, 2020 at 21:01
  • What's wrong on HttpUtility.HtmlDecode Method (as @Mikael already suggested)?
    – JosefZ
    Commented Aug 15, 2020 at 11:02
  • HttpUtility.HtmlDecode Method does not working, it returns the same string as input, i readed that C# native code does not work with html5 tags. Commented Aug 17, 2020 at 17:25

2 Answers 2

1

Using jquery i got the solution:

var ltxtComment_Lmt = document.getElementById('txtComment_Lmt');
ltxtComment_Lmt.value = $('<textarea />').html(ltxtComment_Lmt.value).text();

But i want this solution in C#, i readed that C# not working with html5 entities, i think that exist some easy solution to decode emoji html codes to a textbox.

3
  • 4
    This belongs as an edit to your question, not an answer. Stack overflow isn't a message board where you make a new entry every time you have something to add to a question or answer.
    – Logarr
    Commented Aug 14, 2020 at 21:36
  • This is a answer, but not the answer i want, i just put this to show to other user's that is possible to solve the issue, i hope someone answer my question with C# code, thanks anyway. Commented Aug 17, 2020 at 17:24
  • No, i'm using jquery, and i want to solve with pure C# / javascript Commented Apr 7, 2021 at 20:05
1
HttpUtility.HtmlDecode("test &#128512;&#128513;&#128514;")

should give you the decoded string you are looking for.

Here is a simple test to check its behavior

public class TestEmoji 
{
  [Test]
  public void TestEncodedEmoji() 
  {
    var encoded = "test &#128512;&#128513;&#128514;";

    var decoded = HttpUtility.HtmlDecode(encoded);

    decoded.Should().Be("test 😀😁😂");
  }
}

by the way I am not sure if you are working on ASP.NET Framework or ASP.NET Core. I tested it on Core.

Not the answer you're looking for? Browse other questions tagged or ask your own question.