2023年Java中的MessageFormat.format用法实例.docx





《2023年Java中的MessageFormat.format用法实例.docx》由会员分享,可在线阅读,更多相关《2023年Java中的MessageFormat.format用法实例.docx(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、2023年Java中的MessageFormat.format用法实例 Java中的MessageFormat.format用法实例 MessageFormat本身与语言环境无关,而与用户提供给MessageFormat的模式和用于已插入参数的子格式模式有关,以生成适用于不同语言环境的消息。下面是我为大家带来的Java中的MessageFormat.format用法实例,欢迎阅读。 Java中的.MessageFormat.format用法实例 MessageFormat本身与语言环境无关,而与用户提供给MessageFormat的模式和用于已插入参数的子格式模式有关,以生成适用于不同语言环境
2、的消息。 MessageFormat模式主要部分: 代码如下: FormatElement: ArgumentIndex :是从0开始的入参位置索引。 ArgumentIndex , FormatType ArgumentIndex , FormatType , FormatStyle FormatType: :指定使用不同的Format子类对入参进行格式化处理。值范围如下: number:调用NumberFormat进行格式化 date:调用DateFormat进行格式化 time:调用DateFormat进行格式化 choice:调用ChoiceFormat进行格式化 FormatStyl
3、e::设置FormatType中使用的格式化样式。值范围如下: short medium long full integer currency percent SubformatPattern 子格式模式,形如. 还以str为例,在这个字符串中: 1、0和1,number,short和2,number,.;都属于FormatElement,0,1,2是ArgumentIndex。 2、1,number,short里面的number属于FormatType,short则属于FormatStyle。 3、1,number,.里面的.就属于子格式模式。 指定FormatType和FormatStyl
4、e是为了生成日期格式的值、不同精度的数字、百分比类型等等。 实例: 1、ArgumentIndex必需是非负整数,它的个数不只限于0到9这10个,它可以用0到9的数字组成,因此可以有好多个,如: 代码如下: String msg = "012345678" Object array = new Object"A","B","C","D","E","F","G","H","I",; String v
5、alue = MessageFormat.formatmsg, array; System.out.printlnvalue; / 输出:ABCDEFGHI 2、格式化字符串时,两个单引号才表示一个单引号,单个单引号会被省略,除非中文单引号不会被省略,如: 代码如下: String value = MessageFormat.format"oh, 0 is &39;a&39; pig", "ZhangSan" System.out.printlnvalue; / 输出:oh, ZhangSan is a pig 给字母a加上单引号,如: 代码如下: St
6、ring value = MessageFormat.format"oh, 0 is &39;&39;a&39;&39; pig", "ZhangSan" System.out.printlnvalue; / 输出:oh, ZhangSan is &39;a&39; pig 假如需要显示双引号要进行转移,比方:String msg = "oh, 0 is "a" pig" 3、单引号会使其后面的占位符均失效,导致直接输出占位符。 代码如下: MessageFormat.format"01", 1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2023 Java 中的 MessageFormat format 用法 实例

限制150内