Skip to content

Instantly share code, notes, and snippets.

@OmerShapira
Created November 13, 2012 01:41
Show Gist options
  • Save OmerShapira/4063334 to your computer and use it in GitHub Desktop.
Save OmerShapira/4063334 to your computer and use it in GitHub Desktop.
Processing Simple Soft Wrap
String wrap(String s, int numChars){
int l = s.length();
if (l <= numChars) {
return s;
} else {
StringBuffer b = new StringBuffer();
char[] charArray = s.toCharArray();
int counter = 0;
for (int i = 0 ; i<l ; i++){
if (charArray[i] == ' ' && counter > numChars){
b.append(" \n");
counter=0;
} else {
b.append(charArray[i]);
counter++;
}
}
return b.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment