在JavaScript中从字符串中删除长破折号? [英] Remove a long dash from a string in JavaScript?

查看:552
本文介绍了在JavaScript中从字符串中删除长破折号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络应用程序中遇到错误,我不知道该如何解决。

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

文本框向我发送长短划线他们的内容(你知道,MS Word有时自动插入的特殊长破折号)。但是,我找不到替代它的方法;因为如果我尝试复制该字符并将其放入JavaScript的str.replace语句,它不会呈现正确,它打破了脚本。

Text boxes are sending me the long dash as part of their content (you know, the special long dash that MS Word automatically inserts sometimes). However, I can't find a way to replace it; since if I try to copy that character and put it into a JavaScript str.replace statement, it doesn't render right and it breaks the script.

如何修复这个?

杀死它的特定字符是 - 。

The specific character that's killing it is —.

推荐答案

此代码可能有助于解决这个问题:

This code might help:

text = text.replace(/\u2013|\u2014/g, "-");

它会替换全部 & ndash; / code>( - )和& mdash; ( - )符号。

It replaces all – (–) and — (—) symbols with simple dashes (-).

演示: http://jsfiddle.net/F953H/

这篇关于在JavaScript中从字符串中删除长破折号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆