Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created October 3, 2010 20:45

Revisions

  1. unclebob created this gist Oct 3, 2010.
    11 changes: 11 additions & 0 deletions Wrapper.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    public class Wrapper {
    public static String wrap(String s, int col) {
    if (s.length() <= col)
    return s;
    int space = (s.substring(0, col).lastIndexOf(' '));
    if (space != -1)
    return (s.substring(0, space) + "\n" + wrap(s.substring(space+1), col));
    else
    return (s.substring(0, col) + "\n" + wrap(s.substring(col), col));
    }
    }