zoukankan      html  css  js  c++  java
  • MessageFomat学习

    MessageFomat 提供了一种以与语言无关的方式生成连接消息的方法。 用它来构造消息,显示给最终用户。

     1.MessageFormat的格式

     MessageFormatPattern:FormatElement ,String

    FormatElement: ArgumentIndex,FormatType,FormatStyle

    ArgumentIndex:从0开始

    FormatType:number,date,time,choice

    FormatStyle:short,medium,long,full,integer,currency,percent

     2.例子

     

     1 public class TestMessageFormat {
     2     public static void main(String[] args) {
     3         //format中pattern{}格式ArgumentIndex,FormatType,FormatStyle
     4         //---------------ArgumentIndex只存在ArgumentIndex时------------------
     5         String format = MessageFormat.format("{0}", 1);
     6         System.out.println(format);
     7         //单引号一起使用,则忽略''之间的内容
     8         String format1 = MessageFormat.format("'}{'0}", 1);
     9         System.out.println("单引号一起使用 "'}{'0}" ,则忽略''之间的内容: " + format1);
    10         //单引号(')单独使用,则忽略全部
    11         String format2 = MessageFormat.format("'{0}", 1);
    12         System.out.println("单引号(')单独使用 "'{0}",则忽略全部: " + format2);
    13         //单写右括号(}) 不会报错
    14         String format3 = MessageFormat.format("{0}}", 1);
    15         System.out.println("单写右括号(}),"{0}}" 不会报错: " + format3);
    16         //单写左侧括号,会报错 java.lang.IllegalArgumentException: Unmatched braces in the pattern.
    17 //        String format4 = MessageFormat.format("{{0}", 1);
    18 //        System.out.println(format4);
    19         //-----------------同时存在ArgumentIndex,FormatType,FormatStyle时
    20         String format4 = MessageFormat.format("{0,number,#.#}", 2.3444);
    21         System.out.println(format4);
    22     }
    23 }

    1
    单引号一起使用 "'}{'0}" ,则忽略''之间的内容: }{0}
    单引号(')单独使用 "'{0}",则忽略全部: {0}
    单写右括号(}),"{0}}" 不会报错: 1}
    2.3

         

        

  • 相关阅读:
    UVALive
    HDU6405 Make ZYB Happy 广义sam
    企业级通用链表雏形
    数据结构与算法-递归的形象化理解
    Pictures & texts synthesiser
    全局变量、局部变量、静态全局变量、静态局部变量在内存里的区别
    LINUX 目录文件结构
    测试
    maven 查找jar包的version
    web.xml文件的web-app标签体各版本的约束
  • 原文地址:https://www.cnblogs.com/coding400/p/8673396.html
Copyright © 2011-2022 走看看