How to convert Persian and Arabic numbers inside a

2020-02-24 16:48发布

How can I convert Persian/Arabic numbers to English numbers with a simple function?

arabicNumbers = ["١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "٠"]
persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"]

It is the same schema, but the code pages are different.

7条回答
兄弟一词,经得起流年.
2楼-- · 2020-02-24 17:42

best way to do that return index of number in array:

String.prototype.toEnglishDigits = function () {
    return this.replace(/[۰-۹]/g, function (chr) {
        var persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
        return persian.indexOf(chr);
    });
};
查看更多
登录 后发表回答