javascript - Cleaning the json string from special chars - Stack Overflow

Im using an API to receive data, several parts cause problem which I need to resolve:"Apple® iPad®

Im using an API to receive data, several parts cause problem which I need to resolve:

"Apple® iPad® 2 with Wi-Fi - 16GB"

"Rocketfish™ - Premium Vehicle Charger for Apple® iPad™, iPhone® and iPod®"

I need to remove special UTF8 chars such as ® ™, how can I achieve this ?

Im using an API to receive data, several parts cause problem which I need to resolve:

"Apple® iPad® 2 with Wi-Fi - 16GB"

"Rocketfish™ - Premium Vehicle Charger for Apple® iPad™, iPhone® and iPod®"

I need to remove special UTF8 chars such as ® ™, how can I achieve this ?

Share Improve this question asked Apr 13, 2012 at 15:36 HellnarHellnar 65k82 gold badges208 silver badges282 bronze badges 2
  • 1 Are you sure that you can't work with those characters? Anyway, what you're looking for isn't a regex but a simple char by char filter. Way faster and way more efficient. – Colin Hebert Commented Apr 13, 2012 at 15:40
  • Duplicated: stackoverflow./questions/3465874/… – lamelas Commented Apr 13, 2012 at 15:41
Add a ment  | 

2 Answers 2

Reset to default 3

if you want to remove all symbols except basic latin just apply a regular expression like

str = str.replace(/[\u0080-\uFFFF]+/g, "");

See this list of unicode characters to choose which characters you need to accept or not

First, please make sure you absolutely cannot work with those "problematic" symbols. Clean modern program should correctly understand input in any language.

As for your request to remove anything unreadable, it is better to specify what you want to leave instead, since F. Calderan's example won't remove any extra Unicode symbols above specified FFFF position. So, considering you only want ASCII:

str = str.replace(/[^\u0000-\u007F]+/g, "");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745035941a4607518.html

相关推荐

  • javascript - Cleaning the json string from special chars - Stack Overflow

    Im using an API to receive data, several parts cause problem which I need to resolve:"Apple® iPad®

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信