split persian(arabic) number with sscanf
Question
i have a persian text like : " ۲۲۸ در صورتي که موضوع تعهد، تأديهي وجه نقدي باشد، حاکم ميتواند با رعايت مادهي ۲۲۱ مديون را به جبران خسارت حاصله از تأخير در تأديه دين محکوم نمايد." and my goal is to split "۲۲۸" that is a number from the main text, if it was a normal english number i could do it easily by
sscanf(text,"%d %[^\t\n]", &a);
but c does not recognize persian number as decimal. so what should i do ?
as i do some research i know that objective-c recognize this text as utf-8, and one way to solve this is to replace numbers with english ones .
La solution
What we do is, to show numbers in Persian but send those numbers in English.
All you have to do is to have a convertor in UI which converts everything to Persian as the user is inputting his text. But send the original text to your app.
If your case is just about numbers, you may want to have a convertor for numbers only.
BTW, it is just the solution we use and is tested. However, you may find a better one.
UPDATED
In this case (that you are unable to modify user's input), you have to try these steps:
First try to understand how these numbers are encoded. Write a sample application which receives Persian numbers as characters and print them to see what they really are
Second have a 2D array consisting of number-encoded-character
and its real value
. Store all of the ten numbers in it.
Third receive the whole text as a string and find numbers in that. (Because now you are able to compare each character by those encoded-number-characters). As soon as there is a match in your look up table, you can have its real value.