Remove a long dash from a string in JavaScript?

后端 未结 4 671
梦如初夏
梦如初夏 2021-02-05 11:05

I\'ve come across an error in my web app that I\'m not sure how to fix.

Text boxes are sending me the long dash as part of their content (you know, the special long dash

4条回答
  •  [愿得一人]
    2021-02-05 11:25

    There may be more characters behaving like this, and you may want to reuse them in html later. A more generic way to to deal with it could be to replace all 'extended characters' with their html encoded equivalent. You could do that Like this:

    [yourstring].replace(/[\u0080-\uC350]/g, 
                          function(a) {
                            return '&#'+a.charCodeAt(0)+';';
                          }
    );
    

提交回复
热议问题