Skip to content

Instantly share code, notes, and snippets.

@cutmail
Created April 8, 2011 07:12
Show Gist options
  • Save cutmail/909427 to your computer and use it in GitHub Desktop.
Save cutmail/909427 to your computer and use it in GitHub Desktop.

Revisions

  1. cutmail created this gist Apr 8, 2011.
    18 changes: 18 additions & 0 deletions trim.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    public static String trimUni(String s){
    int len = s.length();
    int st = 0;
    char[] val = s.toCharArray();

    while (st < len && (val[st] <= ' ' || val[st] == ' ')) {
    st++;
    }
    while (st < len && (val[len - 1] <= ' ' || val[len - 1] == ' ')) {
    len--;
    }

    if(st > 0 || len < s.length()) {
    return s.substring(st, len);
    }

    return s;
    }