Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cutmail
Created April 8, 2011 07:12
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 cutmail/909427 to your computer and use it in GitHub Desktop.
Save cutmail/909427 to your computer and use it in GitHub Desktop.
全角スペースもtrimしちゃう
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment