【问题标题】:JS - Convert Special Tilde Characters etc? [duplicate]JS - 转换特殊波浪字符等? [复制]
【发布时间】:2018-03-10 15:25:27
【问题描述】:

是否可以将ñ、á、é等字符转换为普通的英文/拉丁字符?

ñ 应该返回 n
á 应该返回一个
é 应该返回 e
等等

【问题讨论】:

标签: javascript


【解决方案1】:

使用替换和正则表达式

var str = "ñ á é ";
undefined
var res = str.replace("ñ", "n").replace("á", "a").replace("é", "e");
undefined
console.log(res);

【讨论】:

    【解决方案2】:

    是的,您可以使用替换方法。 例如

    var string = "Buenos días.";
    
    var new_string = string.replace('í', 'i');
    
    console.log(new_string)

    如果您想添加更多字符,您可以在 new_string 末尾添加另一个 .replace 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-01
      • 2013-08-23
      • 2017-05-02
      • 1970-01-01
      • 2012-12-04
      • 2013-10-03
      • 1970-01-01
      • 2022-07-10
      相关资源
      最近更新 更多