Formatting made (not) easy

Formatting a telephone number, the hard way ….


  private function telephoneText(mytext:String):String
  {
 
      var split:String;
      var mytext:String = new String(mytext);
 
      var myArray:Array = mytext.split("\r");
      mytext = myArray.join(" ");
      myArray = mytext.split("\n");
      mytext = myArray.join(" ");
 
      myArray = mytext.split("     ");
      mytext = myArray.join(" ");
 
      myArray = mytext.split("    ");
      mytext = myArray.join(" ");
 
      myArray = mytext.split("   ");
      mytext = myArray.join(" ");
 
      myArray = mytext.split("  ");
      mytext = myArray.join(" ");
 
      myArray = mytext.split(" ");
      mytext = myArray.join("");
 
      split = mytext.substr(0, 3) + " " + mytext.substr(3, 2) + " " + mytext.substr(5, 3);
      mytext = split;
      return mytext;
  }

Source : Github Gist