Java Reference
In-Depth Information
public void parseAndReformat(String locale, String number,
String[] locales)
throws ParseException
{
Locale loc = LocalNumber.parseLocale(locale);
NumberFormat parser = NumberFormat.getInstance(loc);
Number num = parser.parse(number);
for (String str : locales) {
Locale pl = LocalNumber.parseLocale(str);
NumberFormat fmt = NumberFormat.getInstance(pl);
System.out.println(fmt.format(num));
}
}
When run with the original locale it_CH , the number string "5'372.97" and
the locale arguments en_US , lv , and lt , parseAndReformat prints:
5,372.97
5 372,97
5.372,97
24.6.3. Text Boundaries
Parsing requires finding boundaries in text. The class BreakIterator
provides a locale-sensitive tool for locating such break points. It has four
kinds of "get instance" methods that return specific types of BreakIter-
ator objects:
getCharacterInstance returns an iterator that shows valid breaks in
a string for individual characters (not necessarily a char ).
getWordInstance returns an iterator that shows word breaks in a
string.
 
Search WWH ::




Custom Search