Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8111531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:09:33+00:00 2026-06-06T02:09:33+00:00

Thanks in advance for your help. I have a need within an application to

  • 0

Thanks in advance for your help.

I have a need within an application to remove all HTML Characters and replace them with their HTML number equivalent.

For example:

‡, •, -, ‰, € and ™

Become:

‡, •, -, ‰, € and ™

There are lot’s of questions currently out there, but these do it the other way round.

I have all of the chars I want to convert in a JSON object (this is just a snapsshot of a much larger list, just to prove my JSON is good):

{"ch":"‘","sub":"‘"},
{"ch":"’","sub":"’"},
{"ch":"‚","sub":"‚"},
{"ch":"“","sub":"“"},
{"ch":"”","sub":"”"},
{"ch":"„","sub":"„"},
{"ch":"†","sub":"†"},
{"ch":"‡","sub":"‡"},
{"ch":"•","sub":"•"},
...

And I currently loop through (using Prototype here) and attempt to replace them:

oJSONItems.each(function(o){
    var oRG = new RegExp(o.ch,'g');
    oText = oText.replace(oRG,o.sub);
});

Some are being replaced, but some are not…

‡
•
-
‰
€
™

More than anything I need to know why chars like ™ are failing to be converted.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:09:37+00:00Added an answer on June 6, 2026 at 2:09 am

    Rather than code for specific entities, how about one that replaces anything outside the original 7 bit ASCII range:

    str = str.replace(/[^\011\012\015\040-\177]/g, function(x) {
        return '&#' + x.charCodeAt(0) + ';'
    })
    

    (The regexp matches anything that’s not white space or a “normal” ASCII character)

    Alternatively, write your map so that the keys are the characters you want to replace, and the values are the entities:

    var map = { '£' : '£' }
    
    str = str.replace(/./g, function(x) {
        return (x in map) ? map[x] : x;
    });
    

    Note that both versions only make the regexp call once, rather than once for each possible entity in your set. This should make the code somewhat faster than your loop-based method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks in advance for your help experts. I want to be able to copy
First off, thanks in advance for your help. This issue is driving me nuts.
Thanks in advance.. I have a windows phone application. In that I am showing
Thanks,in advance I want to remove all the zero size files in specified directory,can
Thanks in advance for your help. I'm completely stumped on how I can do
thanks in advance for the replies.... I have started to create a network topology
(Thanks in advance! Please let me know if you need more info. Sample code
I have a batch file that I need to run within my NSIS installer.
I need to migrate a ASP.NET application from 1.1 to 3.5. I have gone
Brain squeeze and need help, I have a table with 6 rows that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.