简体   繁体   中英

How to convert from full-width to half-width Japanese characters in Java?

I'm using class Transliterator of the icu project to convert from half-width to full-width characters like this:

Transliterator transliterator = Transliterator.getInstance("Hiragana-Katakana");
String converted = transliterator.transliterate("コンニチハ");  //half-width

The result of converted is: コンニチハ (full-width)

But:

String converted = transliterator.transliterate("コンニチハ");  //full-width

The result of converted is still: コンニチハ (full-width)

My expectation isコンニチハ. Can anyone help me solve this?

Thanks.

I found the answer here . It's so simple by using different params as below:

Transliterator transliterator = Transliterator.getInstance("Halfwidth-Fullwidth");
String converted = transliterator.transliterate("コンニチハ");  //half-width

converted value: コンニチハ

Transliterator transliterator = Transliterator.getInstance("Fullwidth-Halfwidth");
String converted = transliterator.transliterate("コンニチハ");  //full-width

converted value: コンニチハ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM