0

Check the following code:

using System;

public class Program
{
    public static void Main()
    {
        string[] myArray = new string[] {"one", "وزارة", "وكيل", "four"};
        string temp = "";

        for(int i=0; i<myArray.Length; i++)
        {       
            if(temp == "")
                temp = myArray[i].ToString();
            else
                temp += "|" + myArray[i].ToString();
        }

        Console.Write(temp);
    }
}

Here's the link to .Net Fiddle.

https://dotnetfiddle.net/q7lHIu

This code is printing all elements in array one by one. The array contain two English and two Arabic words. Problem is as soon as you change the last element to start with number, it messes up everything.

For e.g. try to change "four" to "4four" and see what happens.

Why is this happening?

Frank Martin
  • 3,147
  • 16
  • 52
  • 73
  • This is because you're mixing ltr (left-to-right) with rtl (right-to-left) languages, typically consoles handle this sort of thing very poorly. The string however still contains what you'd expect it to. – Benjamin Gruenbaum Apr 12 '15 at 12:52
  • Try `Console.OutputEncoding = System.Text.Encoding.Unicode;` before your Console.WriteLine – Benjamin Gruenbaum Apr 12 '15 at 12:54
  • Found solution here http://stackoverflow.com/questions/25979638/insert-integer-to-arabic-string-in-start – Frank Martin Apr 12 '15 at 12:55

0 Answers0