Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created October 3, 2010 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclebob/608834 to your computer and use it in GitHub Desktop.
Save unclebob/608834 to your computer and use it in GitHub Desktop.
public class Wrapper {
public static String wrap(String s, int col) {
if (s.length() <= col)
return s;
else {
int lastSpace = 0;
int space;
while ((space = s.indexOf(" ", lastSpace)) != -1) {
if (space > col) {
s = s.substring(0, lastSpace) + "\n" + s.substring(lastSpace+1);
//todo this doesn't look right.
}
lastSpace = space;
}
return s; // really?
}
// return s.replaceAll(" ", "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment