...
Code Block | ||
---|---|---|
| ||
public static String trim_good(String string) { BreakIterator iter = BreakIterator.getCharacterInstance(); iter.setText(string); for (int i = iter.first(); i != BreakIterator.DONE; i = iter.next()) { int ch = string.codePointAt(i); if (!Character.isLetter(ch)) { break; } if (i == BreakIterator.DONE) { // first or last text boundary has been reached return ""; } else { return string.substring(i); } } return string; } |
To perform locale-sensitive String
comparisons for searching and sorting, use the java.text.Collator
class.
Risk Assessment
Failure to account for supplementary and combining characters can lead to unexpected behavior.
...