Mathematical operations on Arabic numbers

You must Login before you can answer or comment on any questions.

Hi

Can you guys please tell how can I process arabic numeric input? The user will be using ARabic keypad and I will have to perform simple operation? Should I detect Unicode? if yes then how do I do it?

— asked 10 months ago by Adnan Ahmad
2 Comments
  • Do you have some sample code? It's really hard to know without having something to work with.

    — commented 10 months ago by Pedro Enrique

  • In arabic you write numbers like ? ? ? ? ? ? ? which is equivalent of ** 1 2 3 4 5 6 7**

    Computer adds integer in English format while user will input in Arabic, how do I add/minus number if they are input in Arabic?

    — commented 10 months ago by Adnan Ahmad

3 Answers

Accepted Answer

Hi Adnan

Sorry for the delay - I had not forgotten.

I have created a proof of concept that should get you started on your solution. This example will take the typed value using a standard keyboard using the Arabic language (not numeric as this stays as Decimal notation numbers).

This relies on a few basic assumptions (on my part as to the needs) I apologise if I have not interpreted this correctly, but hopefully this will help you.

This is what it does.

  1. This will find any Arabic numbers which are swapped using regular expressions.
  2. Find and matches any numeric blocks which are now in non-arabic numbers
  3. Reverse any numeric block - so 123 becomes 321
  4. The resulting string is returned
  5. In this case shown in the label view.

Add this code to a blank window called win.

var lbl = Ti.UI.createLabel({
    font: {
        fontSize: 20
    },
    height: Ti.UI.SIZE,
    text: 'Result',
    top: 10,
    width: Ti.UI.SIZE
});
win1.add(lbl);
var txt = Ti.UI.createTextField({
    borderWidth: 1,
    font: {
        fontSize: 20
    },
    height: 50,
    top: 60,
    value: '\u0660\u0661\u0662+\u0663\u0664\u0665+\u0666\u0667', //123+456+67
    width: 200
});
win1.add(txt);
var btn = Ti.UI.createButton({
    font: {
        fontSize: 20
    },
    height: Ti.UI.SIZE,
    title: 'Try',
    top: 120,
    width: 200
});
win1.add(btn);
btn.addEventListener('click', function (E) {
    var val = txt.getValue();
 
    val = val.replace(/\u0660/gim, '0');
    val = val.replace(/\u0661/gim, '1');
    val = val.replace(/\u0662/gim, '2');
    val = val.replace(/\u0663/gim, '3');
    val = val.replace(/\u0664/gim, '4');
    val = val.replace(/\u0665/gim, '5');
    val = val.replace(/\u0666/gim, '6');
    val = val.replace(/\u0667/gim, '7');
    val = val.replace(/\u0668/gim, '8');
    val = val.replace(/\u0669/gim, '9');
 
    function reverseStr(str) {
        var s = "";
        var i = str.length;
        while (i>0) {
            s += str.substring(i-1,i);
            i--;
        }
        return s;
    }
    var sum = val;
    reg = new RegExp(/\d{1,10}/g);   
    var result;
    while((result = reg.exec(sum)) !== null) {
        sum = sum.replace(result[0], reverseStr(result[0]));
    }
 
 
    lbl.setText(sum);
});
You should be able run the eval command on the result so it will answer the equation that was typed.

Let me know if this helps.

Hi Adnan

Which specific language/keyboard - Arabic numerals, Eastern Arabic numerals or other? Are you planning on iPhone, Android or both?

The iPhone keyboard appears to use the Eastern Arabic numerals, example here.

I have the basis of an idea - but depends on your answers.

Would the numbers also be written in reverse? So 123 (one hundred and twenty three) would be written as 321 or 123?

I have had a play with a solution and I have something that should be able to do it, I will play a little more when I have your answer and then let you have the code to play with yourself.

Your Answer

Think you can help? Login to answer this question!