code_junkie

Problem trimming Japanese string in java

Nov 13th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. " ユーザー名".replaceAll("\p{Z}", "")
  2.  
  3. " ユーザ ー名 ".replaceAll("(^\p{Z}+|\p{Z}+$)", "")
  4.  
  5. int character = 12288;
  6. char[] ch = Character.toChars(character);
  7. String input = new String(ch);
  8. String normalized = Normalizer.normalize(input, Normalizer.Form.NFKC);
  9.  
  10. System.out.println("Hex value:t" + Integer.toHexString(character));
  11. System.out.println("Trimmed length :t"
  12. + input.trim().length());
  13. System.out.println("Normalized trimmed length:t"
  14. + normalized.trim().length());
Add Comment
Please, Sign In to add comment