Last active
August 6, 2020 10:56
-
-
Save zumoshi/cb04825699693f33b081 to your computer and use it in GitHub Desktop.
Convert Persian Numbers to Latin Numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| tabdil('۲۰۲۷۰۱-۱-۳۸۱-۹۴۳۸۲') => "202701138194382" | |
| */ | |
| var tabdil=function(m){ | |
| var num=JSON.parse('{"۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"}'); | |
| return m.replace(/./g,function(c){ | |
| return (typeof num[c]==="undefined")? | |
| ((/\d+/.test(c))?c:''): | |
| num[c]; | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function num(s){ | |
| var a=["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"] | |
| var p=["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"] | |
| for(var i=0;i<10;i++){ | |
| s=s.replace(new RegExp(a[i],'g'),i) | |
| .replace(new RegExp(p[i],'g'),i) | |
| } | |
| return s; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yes it works, it seems that a denotes to Arabic and p denotes to Persian digits