javascript如何把汉字转化为数字,比如一二三三九一转化成123391
展开全部
function _convert(str)
{
var arr = ["一","二","三","四","五","六","七","八","九","十"];
for (var i = 0; i < arr.length; i++) {
str = str.replace(new RegExp(arr[i], "g"), (i+1));
}
return str;
}
// 使用
var str = "一二三三九一";
var result = _convert(str);
result // 123391
追问
要加零呢
追答
var arr = ["零","一","二","三","四","五","六","七","八","九","十"];
...
str = str.replace(new RegExp(arr[i], "g"), (i));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询