javascript如何把汉字转化为数字,比如一二三三九一转化成123391
答案:2 悬赏:40 手机版
解决时间 2021-03-27 09:35
- 提问者网友:嘚啵嘚啵
- 2021-03-26 10:34
javascript如何把汉字转化为数字,比如一二三三九一转化成123391
最佳答案
- 五星知识达人网友:第四晚心情
- 2021-03-26 11:08
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));
{
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));
全部回答
- 1楼网友:患得患失的劫
- 2021-03-26 11:21
成123391成123391成123391
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯