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

         

        

  • 相关阅读:
    VUE中全局变量的定义和使用
    Pull Request 工作流——更高效的管理代码
    仓储repository概念
    Mysql存储过程历史表备份
    OpenStack一键安装
    VMware虚拟机设置Win10固定ip
    C#_NPOI_Excel各种设置
    pycharm修改镜像
    C#模拟POST上传文件帮助类(支持https、http)
    Windows安装RabbitMQ
  • 原文地址:https://www.cnblogs.com/coding400/p/8673396.html
Copyright © 2011-2022 走看看