0

Note 2: I found the answer - and it wasn't anywhere else on your site. You mark things as duplicates far too cavalierly. Here was the line that fixed my problem. Where is it on your site?

str = str.replace(/\u2019/g, "'");

Note: This is not a duplicate of "Remove accents/diacritics in a string in JavaScript." My question has to do with a sole apostrophe and not an accent or diacritic.

I have an HTML input field being used on an iPhone. The person is typing the word "don't." The apostrophe is coming across as 0xE2 0x80 0x99. I presume that is Unicode. How can I convert that to an ASCII single quote in JavaScript?

I am basically looking to create a JavaScript function that takes a string (potentially containing any number of those Unicode apostrophes) and returns the string with all of the Unicode apostrophes replaced with the ASCII single quotes in their places.

Thank you!

Blake McBride
  • 394
  • 3
  • 16
  • FYI, `E2 80 99` are the UTF-8-encoded bytes for `’` – Mark Tolonen Dec 05 '22 at 22:48
  • While this is indeed wrongly closed as duplicate I'm disappointed to see 9+ years of membership and yet not using one single formatting. Your solution will also replace legal quotation marks and miss [a lot of similar characters](https://en.wikipedia.org/wiki/Apostrophe#Unicode) that users might mix in instead of correct apostrophes, most prominently accute `´` and gravis `\``. – AmigoJack Dec 06 '22 at 21:38
  • As a side note, after 40 years as a software engineer, I rarely ask basic questions. It is disappointing that all too often my questions get incorrectly marked as duplicates. This causes me to use StackOverflow as a very last resort. – Blake McBride Dec 08 '22 at 01:47

0 Answers0