Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes How to get List Separator of local system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get List Separator of local system" Watch "How to get List Separator of local system" New topic
Author

How to get List Separator of local system

Justin Jin
Greenhorn

Joined: Sep 04, 2003
Posts: 2
Hi, all,
I want to get the List separator of the local system in my applet, and I can get it using this:
ResourceBundle rb = ResourceBundle.getBundle
("java.text.resources.localeElements",Locale.getDefault());
String[] elmArr = rb.getStringArr("NumberElements");
char listSeparator = elmArr[2].charAt(0);
it works good when I use MS JVM or sun plugin 1.3, but when I use sun plugin1.4 to test it, it throw exception, because java.text.resources.localeElements doesn't exist in jdk1.4.
So my question is how to get this List separator in both case(support jdk1.1 to jdk1.4)?
Thanks anvance
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
The resource bundle that you were using has been moved into a "sun" package, and it is not recommended that you use them. However there is an easier way that will work in any JDK, which is to use the "java.text.DecimalFormatSymbols" class. There is a default constructor which will use the current locale, and a constructor that takes a locale. Once you have the instance you can call methods to get the currency symbol, decimal separator, grouping separator, etc. Look at the JavaDoc for the "java.text.DecimalFormatSymbols" class.

Cheers!
[ September 04, 2003: Message edited by: Wayne L Johnson ]
Justin Jin
Greenhorn

Joined: Sep 04, 2003
Posts: 2
Hi,Wayne,
Thanks for reply, but the problem is when I use DecimalFormatSymbols like below:
DecimalFormatSymbols tempdfs = new DecimalFormatSymbols
(Locale.getDefault());
char tempDS = tempdfs.getDecimalSeparator();
char tempGS = tempdfs.getGroupingSeparator();
char tempLS = tempdfs.getPatternSeparator();
tempDS and tempGS is correct, but tempLS always return ';", no matter what setting is.
for example, in control panel, when I change regional option to canada, the List separator shoud be ',', but what I get is still tempLS=';' , so how can i get List separator? maybe the method of getPatternSeparator is not the right method to get List Separator?
[ September 04, 2003: Message edited by: Justin Jin ]
 
GeeCON Prague 2014
 
subject: How to get List Separator of local system