MessageFormat(动态文本)
来源:互联网 发布:sql统计数量 编辑:程序博客网 时间:2024/06/05 17:56
MessageFormat(动态文本)
1、 如果一个字符串中包含了多个与国际化相关的数据,可以使用MessageFormat类对这些数据进行批量处理。
例如:At 12:30 pm on jul 3,1998, ahurricance destroyed 99 houses and caused $1000000 of damage
以上字符串中包含了时间、数字、货币等多个与国际化相关的数据,对于这种字符串,可以使用MessageFormat类对其国际化相关的数据进行批量处理。
2、 MessageFormat 类如何进行批量处理呢?
1)MessageFormat类允许开发人员用占位符替换掉字符串中的敏感数据(即国际化相关的数据)。
2)MessageFormat类在格式化输出包含占位符的文本时,messageFormat类可以接收一个参数数组,以替换文本中的每一个占位符。
模式字符串: {0}、{1}、{2}占位符
At {0}, a hurricance destroyed {1} houses and caused{2} of damage
String pattern="At {0,time,short} on {0,date,long}, a hurricancedestroyed {1,number} houses and caused{2,number,currency} of damage";
MessageFormat mf=new MessageFormat(pattern,Locale.US);
Object []objs={new Date(),new Integer(99),new Double(1e7)};
String result=mf.format(objs);
System.out.println(result);
ResourceBundle bundle=ResourceBundle.getBundle("com.hbsi.resource.MyResource",Locale.CHINA);
result=bundle.getString("title");
//System.out.println(result);
MessageFormat mf1=new MessageFormat(result,Locale.CHINA);
System.out.println(mf1.format(objs));
- MessageFormat(动态文本)
- 国际化动态文本(MessageFormat)
- MessageFormat(动态文本)
- MessageFormat(动态文本)
- MessageFormat(动态文本)
- 国际化动态文本(MessageFormat)的使用案例源码和国际化其他标签的使用
- Java常用类库——国际化程序(Locale,ResourceBundle以及MessageFormat处理动态文本)
- MessageFormat字符串动态设置值
- MessageFormat
- MessageFormat
- MessageFormat妙用
- MessageFormat用法
- java MessageFormat
- MessageFormat用法
- MessageFormat妙用
- MessageFormat用法
- MessageFormat用法
- MessageFormat用法
- 用java SWT制作的一个模仿微软的计算器,1000行代码!
- php中socket方式发送邮件代码示例
- 基于postgreSQL9.1的中文全文检索(基于Linux)
- 顶部小图片鼠标经过效果:
- 编写高效Lua代码的方法 - 4 - 减少,重用,回收
- MessageFormat(动态文本)
- hibernate.cfg.xml配置总结(数据库连接池) .
- 出现/bin/sh: can't access tty; job control turned off的解决方案
- MCS-51单片机的存储器组织结构
- MySpaceV1.02 测试版发布
- 深入理解void类型
- JSTL函数
- js2c#
- XtraTreeList使用扎记(1)