2

There is a requirement to write many Arabic words and english words along with numerical digits without using any special character in between. Initially I used U+202C(pop directional formatting code) whenever I detected an Arabic text. However that is injecting those extra non-printable characters in the file which is not acceptable. The size of the file has to be maintained strictly with the protocol defined by bank systems. Where every bit position has to exactly follow a specific no. of characters. Later I optimised my solution by injecting one character at the start of a line. I could not find any solution to this problem yet without injecting any character. Any possible solution would be very helpful.

            String arabicStr ="المهتار";
            String englishStr = "6abc";
            System.out.println("Without any special character injected");
            System.out.println(arabicStr+englishStr);
            
            // Creating array of string length
            char[] ch = new char[arabicStr.length() + englishStr.length()+1];
            // Force following characters to be treated as strong left-to-right characters.
            ch[0] = '\u202D';
            // Copy Arabic character by character into array, in reverse direction
            int i =0;
            int j =1;
            for (i = arabicStr.length()-1; i >=0 ; i--) {
                ch[j] = arabicStr.charAt(i);
                j++;
            }
            i= arabicStr.length()+1;
            for(int n =0; n<englishStr.length(); n++ )
            {
                ch[i]=englishStr.charAt(n);
                i++;
            }
            System.out.print("With strict left to right reversed Arabic: "); 
            for (int pos =0; pos< ch.length; pos++ ) {
                System.out.print(ch[pos]);
            }

output

Without any special character injected
المهتار6abc
With strict left to right reversed Arabic: ‭راتهملا6abc

So what I did is, applied strict left to right throughout the text irrespective of Arabic or English and reversed Arabic text. This issue comes, only when we have letters followed by Arabic words. Based on some search it seems Bidirectional algorithm could not determine whether the digits are part of Arabic or English words. https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Bidirectional_neutral_formatting

0 Answers0