Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Created June 14, 2011 02:30
Show Gist options
  • Select an option

  • Save zeuxisoo/1024198 to your computer and use it in GitHub Desktop.

Select an option

Save zeuxisoo/1024198 to your computer and use it in GitHub Desktop.
Add space between words
function space_text(my_text){
var len = my_text.length;
var text = my_text;
var text2 = text.charAt(0);
for(var i = 1; i < len-1; i++) {
text2 += text.charAt(i);
if(text.charCodeAt(i) > 128 && text.charAt(i+1) != " " && text.charAt(i+1) != "\n")
text2 += " ";
}
text2 += text.charAt(len-1);
len = text2.length;
var text3 = text2.charAt(0);
for(var i = 1; i < len-1; i++) {
if(text2.charCodeAt(i) > 128 && text2.charAt(i-1) != " " && text2.charAt(i-1) != "\n") {
text3 += " ";
}
text3 += text2.charAt(i);
}
text3 += text2.charAt(len-1);
return text3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment