title: C# Algorithm for converting Visual LTR to Logic RTL
body: <p>Iam working on a project in Unity3d, using C# scripting, with strings that are written in Hebrew and English.
  The problem with Unity3d is that RTL languages (like Hebrew) are not supported when writing UI texts.</p>
  
  <p>The problem looks like this:
  original text:
  מערכת העטלף הינה מערכת, אשר מתבססת על טכנולוגית ה- GPR 
  (Ground Penetrating Radar) - ראדאר חודר קרקע.</p>
  
  <p>in unity:
  GPR -ה תיגולונכט לע תססבתמ רשא ,תכרעמ הניה ףלטעה תכרעמ
  .עקרק רדוח ראדאר - (Ground Penetrating Radar)</p>
  
  <p>Iam trying to hack the order that the text is printed to the text boxes for a month now and I cant get it just right.
  I made up the following function:</p>
  
  <pre><code>    public string CorrectText (string text)
  {
      string result = "";
      string temp = "";
      string charListString = "";
      List&lt;Char&gt; charList = new List&lt;char&gt; ();
      char[] charArray = text.ToCharArray ();
  
      Array.Reverse (charArray);
  
      //go through each char in charArray
      for (int x = 0; x &lt;= charArray.Length -1; x++) {
          //if the current char we're examing isn't a Space char -
          if (!char.IsWhiteSpace (charArray [x])) {
              //add it to charList
              charList.Add (charArray [x]);
          } else { //if the current char we're examing is a Space char -
              charListString = new string (charList.ToArray ());
  
              //if charListString doesn't contains English or Numeric chars -
              if (!Regex.IsMatch (charListString, "^[0-9a-zA-Z.,()-]*$")) {
                  //go through each char in charList 
                  for (int y = 0; y &lt;= charList.Count - 1; y++) {
                      //add the current char to temp as is (not flipped)
                      temp += charList [y];
                  }
  
                  //add temp to result
                  if (x &lt; charArray.Length - 1)
                      result += temp + " ";
                  if (x == charArray.Length - 1)
                      result += temp;
  
                  //clear charList and temp
                  charList.Clear ();
                  temp = "";
              } else { //if temp contains English or Numeric chars -
                  //go through each char in charList - This flipps the order of letters
                  for (int y = charList.Count - 1; y &gt;= 0; y--) {
                      //add the current char to temp
                      temp += charList [y];
                  }
  
                  //add temp to result
                  if (x &lt; charArray.Length - 1)
                      result += temp + " ";
                  if (x == charArray.Length - 1)
                      result += temp;
                  //clear charList and temp
                  charList.Clear ();
                  temp = "";
              }
          }
  
      }
  
      return result;
  }
  </code></pre>
  
  <p>this almost fixed the problem, but the text is written from bottom up for example:</p>
  
  <p>input:
  מערכת העטלף הינה מערכת, אשר מתבססת על טכנולוגית ה- GPR 
  (Ground Penetrating Radar) - ראדאר חודר קרקע.</p>
  
  <p>output:
  (Ground Penetrating Radar) - ראדאר חודר קרקע.
  מערכת העטלף הינה מערכת, אשר מתבססת על טכנולוגית ה- GPR </p>
  
  <p>and sometimes the parenthesis are getting mixed up in the sentence, showing like this:
  )Ground Penetrating( Radar - ראדאר חודר קרקע.</p>
  
  <p>I've found a tool online that turns Visual Hebrew to Logic Hebrew, and when I copied the flipped text to unity it worked like magic!</p>
  
  <p>But I cant find any useful information online on how to make my own script with C# that does the  same thing.</p>