2

または: これを達成できる、文字列の書式設定と文字列の解析(同じオブジェクトを使用!)の両方が可能な別のユーティリティはありますか?

.au次のパターンの名前を持つ形式のオーディオ ファイルでいっぱいのディレクトリがあるとしますcountry.code.XX.auMessageFormatwith パターンを使用して、これらのファイル名の重要な部分をフォーマットして解析したい場合がありますcountry.{0}.au

しかし、このデモを考えてみてください:

public class MessageFormatExercise {
    public static void main(String[] args) throws Exception {
        java.text.Format f = new java.text.MessageFormat("country.{0}.au");

        // String formatting; prints "country.code.us.au" and "country.code.au.au" respectively
        System.out.println(f.format(new Object[]{"code.us"}));
        System.out.println(f.format(new Object[]{"code.au"}));

        // String parsing; prints "code.us" and "code" respectively (not "code.au"!)
        System.out.println(((Object[]) f.parseObject("country.code.us.au"))[0]);
        System.out.println(((Object[]) f.parseObject("country.code.au.au"))[0]);
    }
}

解析結果に一貫性がありません。code.usorを取得する場合もありますcode.gbが、オーストラリアの場合は単純に を取得しますcode

4

0 に答える 0