Autoformat text


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function autoFormat(what:String, numSpaces:Number):String {
  2. var tmp:Array = what.split(".");
  3. if (!numSpaces) {
  4. numSpaces = 1;
  5. }
  6. var tmpStr:String = "";
  7. for (var i:Number = numSpaces; i>0; i--) {
  8. tmpStr += " ";
  9. }
  10. for (var i in tmp) {
  11. while (tmp[i].charAt(0) === " ") {
  12. tmp[i] = tmp[i].slice(1, tmp[i].length);
  13. }
  14. tmp[i] = tmp[i].charAt(0).toUpperCase()+tmp[i].slice(1, tmp[i].length);
  15. }
  16.  
  17. return tmp.join("."+tmpStr).split(" i ").join(" I ").split(" i'").join(" I'");
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.