Get numeric codepage from java Charset object

855 views Asked by At

How can I get the numeric codepage identifier associated with a Charset object in java (ie. 1252) ?. I can call to displayName() method but it returns alphanumeric identifiers (like "windows-1252", "cp-1252", "CP1252", ...), not only the int code.

In .NET exists an integer CodePage property in Encoding class, but I can't find an equivalent method in Java.

Thanks.

1

There are 1 answers

0
S. Cambon On

From the examples you give, you may use a regular expression:

private static final Pattern NUMERIC_CODEPAGE_PATTERN = Pattern.compile("[^\\d]*(\\d+)");

...

String displayName = charSet.displayName();
Matcher matcher = NUMERIC_CODEPAGE_PATTERN.matcher(displayName);
if(matcher.matches())
{
  String numericCodeString = matcher.group(1);
  int numericCode = Integer.parseInt(numericCodeString);
}