Reputation: 57
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?
Upvotes: 1
Views: 1648
Reputation: 2999
HttpUtility.HtmlDecode("test 😀😁😂")
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 😀😁😂";
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.
Upvotes: 1
Reputation: 57
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.
Upvotes: 1