Get numeric codepage from Java Charset object

How can I get the numerical codepage identifier associated with a Charset object in java (i.e. 1252) ?. I can call the displayName () method, but it returns alphanumeric identifiers (for example, "windows-1252", "cp-1252", "CP1252", ...), and not just int code.

In .NET, there is an integer CodePage property in the Encoding class, but I cannot find an equivalent method in Java.

Thank.

+3
source share
1 answer

From the above examples, you can use the 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);
}
0
source

Source: https://habr.com/ru/post/1788593/


All Articles