Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,
How can change Persian numbers to English numbers in vb.net?
When I read any Persian numbers from an excel file, I want to change them to English numbers.
Thanks.
Posted
Updated 19-Aug-14 7:12am
v2
Comments
Sergey Alexandrovich Kryukov 18-Aug-14 13:10pm    
There are no Persian or English numbers, there are Persian and English numerals, that is, characters.
Now, as to the Persian numerals, the are either "Western Arabic numerals" or "Eastern Arabic numerals". Please see:
http://en.wikipedia.org/wiki/Western_Arabic_numerals,
http://en.wikipedia.org/wiki/Eastern_Arabic_numerals.
If those are what you mean, the are quite easy to convert... What did you try?
If not, what did you mean?
—SA

1 solution

Let's assume you need to convert Eastern Arabic to Western.

Look for example, at this table:
http://persian.nmelrc.org/persianword/numbers.htm[^].

You can see that the code points go in the same order without the gaps, in both "Western" and "Eastern". This is nothing but a shift of 1728.
So, one of the ways to convert it:
C#
static readonly int easternToWesternShift =
    (int)'٠' - (int)'0'; // two zeros

static char EasternToWestern(char eastern) {
    return (char)(eastern - easternToWesternShift);
}

And the like… And so on…

—SA
 
Share this answer
 
v2
Comments
Maciej Los 19-Aug-14 11:07am    
+5
Sergey Alexandrovich Kryukov 19-Aug-14 11:23am    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900