0

Im making an app that makes Arabic letters tall(by adding this ــــ after each letter) so i have to replace every signle letter(about 24 letters). I've created an array this way:

String sub ="ــــ";
String arabicLetters="ج@ح@خ@@ه@ع@غ@ف@ق@ث@ص@ض@ط@ك@م@ن@ت@ل@ب@ي@س@ش@ظ@ئ"; //Will be splitted by split("@")
  String arabicLettersArr[];
arabicLettersArr=arabicLetters.split("@");

Now i have done the array.

Here is the replacing function:

public void makeLettersTall(View v){

        String text = edt.getText().toString().trim();
        if(!text.equals("")){
            for(String letter: arabicLettersArr){           
                    text = text.replace(letter,letter+sub);
            }
            edt.setText(text);
        }
    }

The problem:

let's say that i entered the letter ب so i expect it to be بــــ but what i get is ــــــــبــــ it seems that this symbole ــــ was added twice before letter and once after while i want to be added only once after😔.

0

2 Answers 2

2

If you take a look at your arabicLetters String, you can see you added '@@' almost at the end without a letter in between, therefore your code will also replace '' with ____ what causes the ــــــــبــــ .

Sign up to request clarification or add additional context in comments.

1 Comment

that @ took from me an hour trying find another way to do that function. But finally that's my only problem tnx.
1

Without understanding Arabic, I guess this should do the job:

private static void arabicLetters() {
        String sub ="ــــ";
        String arabicLetters="ج@ح@خ@ه@ع@غ@ف@ق@ث@ص@ض@ط@ك@م@ن@ت@ل@ب@ي@س@ش@ظ@ئ"; //Will be splitted by split("@")
        String[] arabicLettersArr=arabicLetters.split("@");
        StringBuilder outString = new StringBuilder();
        for(String letter: arabicLettersArr)
            outString.append(letter).append(sub);
        System.out.println("result: " + outString.toString());
}

The problem with your code is

text = text.replace(letter,letter+sub);

which replaces a charater globally, i.e. if the same character appears more than once, it will be extended by _____ more than once

2 Comments

The problem was the extra "@". OP wants to add "____" only for the arabic letters that exist on the text.
isn't this code will append all letters?.. anyway everything was fine. my problem was in the Arabic string where i added @ Twice without any letter between them.😅😅

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.