【问题标题】:Get numeric codepage from java Charset object从 java Charset 对象获取数字代码页
【发布时间】:2011-01-28 21:00:16
【问题描述】:

如何获取与 java 中的 Charset 对象关联的数字代码页标识符(即 1252)?我可以调用 displayName() 方法,但它返回字母数字标识符(如“windows-1252”、“cp-1252”、“CP1252”……),而不仅仅是 int 代码。

在 .NET 中 Encoding 类中存在一个整数 CodePage 属性,但我在 Java 中找不到等效方法。

谢谢。

【问题讨论】:

    标签: java encoding character-encoding codepages


    【解决方案1】:

    从你给出的例子中,你可以使用正则表达式:

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多