String.format
来源:互联网 发布:魅可mac什么档次 编辑:程序博客网 时间:2024/04/30 15:05
/*demo1*/
String stringFormat = "站位符 [ %s ],占位符 [ %s ]";
System.out.println(String.format(stringFormat,1,2));
/*demo2*/
String messageFormat ="但前时间 [ {0} ], 占位符[ {1} ], 占位符[ {2} ]";
System.out.println(MessageFormat.format(messageFormat, new Date(), 1, 2));
/*demo3*/
String s = "我是{0},我来自{1},今年{2}岁";
String arr2[] = new String[] { "日本人", "大阪", "22"};
while (s.indexOf("{") != -1) {
int n = Integer.parseInt(s.substring(s.indexOf("{") + 1, s.indexOf("{") + 2));
String s1 = s.substring(s.indexOf("{"), s.indexOf("}") + 1);/*{0}....*/
String s2 = arr2[n];/*{日本人,大阪,22*/
s = s.replace(s1, s2);/*替换*/
}
System.out.println(s);
/*demo4*/
String stringFormat = "站位符 [ %s ],占位符 [ %s ]";
System.out.println(String.format(stringFormat,1,2));
/*demo2*/
String messageFormat ="但前时间 [ {0} ], 占位符[ {1} ], 占位符[ {2} ]";
System.out.println(MessageFormat.format(messageFormat, new Date(), 1, 2));
/*demo3*/
String s = "我是{0},我来自{1},今年{2}岁";
String arr2[] = new String[] { "日本人", "大阪", "22"};
while (s.indexOf("{") != -1) {
int n = Integer.parseInt(s.substring(s.indexOf("{") + 1, s.indexOf("{") + 2));
String s1 = s.substring(s.indexOf("{"), s.indexOf("}") + 1);/*{0}....*/
String s2 = arr2[n];/*{日本人,大阪,22*/
s = s.replace(s1, s2);/*替换*/
}
System.out.println(s);
/*demo4*/
0 0
- String.Format
- string.format()
- string format
- string.Format
- String.format()
- String.Format
- String format
- string.Format
- string.Format
- string.format
- string.Format
- String.format
- String Format
- String format
- String.format()
- String.format()
- string.format()
- format string
- 消息队列RabbitMQ入门介绍
- C代码风格
- 战略变革!微软Office for iPad免费下载
- 腾讯电脑管家 for mac v1.0.0 官方版
- 【乘式还原】 A代表数字0~9中的前5个数字,Z代表后5个数字,请还原下列乘式。
- String.format
- struts2入门
- web.config 中SessionState的配置
- PPTV网络电视2013 v3.5.1.0029 官方最新版
- java concurrent的理解
- Hibernate——(3)主键生成方式
- 中断系统基本原理
- C++ string总结(适合新手)
- 腾讯qq浏览器2014 v7.6.21433 官方版