1

The character set is mentioned at Special Character Map. I need a Java-script or J-Query encoding code to get entity name.

for e.g. if I pass £ then I should get "&pound ;" or for ¥ it should return "&yen ;".

Even I copy the symbols instead of typing in then also it should work.

I am trying to use following J-Query code but it doesn't seem to work when I copy-paste strings.

function krEncodeEntities() {
            var s = $('#input').val();
            return $('#lblEncode').text($("<div/>").text(s).html());
        }
        function krDencodeEntities() {
            var s = $('#lblEncode').text();
            return $('#lblDecode').text($("<div/>").html(s).text());
        }

Can anyone please help me?

Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44
  • What would you do with the entity name? Note that different versions of HTML have different sets of entities. Also clarify how C# is relevant here or remove the c#-4.0 tag. – Jukka K. Korpela May 30 '14 at 07:12
  • @JukkaK.Korpela In the project that i am will putting the code, I will be saving the entity name in the IBM Main frame. Currently main frame doesn't support saving special characters. Hence I want to do encoding and decoding at js side and pass to Main frame via C# code. If its not possible through js, i wondered if it can be done through C# code behind... Hence I added C# tag... – Pratik Gaikwad May 30 '14 at 18:45
  • There should be no need to store the entity name, since you can store the Unicode number of the character. And you should do that server-side, without even considering client-side JavaScript. – Jukka K. Korpela May 30 '14 at 19:24

1 Answers1

0

JavaScript has no concept of HTML identities. To JS, everything is UCS16 (a forerunner of UTF16).

You have a couple of options.

Option 1

Make a big translation object of characters and their identities.

Option 2

See if some other form of encoding will work for you.

When are you supposed to use escape instead of encodeURI / encodeURIComponent?

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74