.Net转Java.08.format
%[index$][标识][最小宽度]转换方式
[index$]可以用于表示对第index个参数进行格式化,
// Java代码
String s1=String.format("%3$s,%2$s,%1$s","a","b","c"); // c,b,a
与C#的索引相比,区别在于C#的索引从0开始,并且是不能省略的
Java的索引是从1开始,并且可以省略
// Java代码
String s1=String.format("%s,%s,%s","a","b","c"); // a,b,c 索引可以省略
System.out.println(s1);
String s2=String.format("%3$s,%2$s,%1$s","a","b","c"); // c,b,a 索引从1开始
System.out.println(s2);
// C#
String result = String.Format("{2},{1},{0}","a","b","c"); // c,b,a 注意索引不能省略,并且从0开始
Console.WriteLine(result);
%s转换方式
其实%s可以转换各种类型,其实就是各种类型的 toString()
// Java代码
String s=String.format("%s,%s,%s,%s,%s","a",1,9.2, LocalDateTime.now(),new Date()); // a,1,9.2,2018-02-03T22:36:01.499,Sat Feb 03 22:36:01 CST 2018
System.out.println(s);
与C#对应的,默认转换方式一样
// C#
String result = String.Format("{0},{1},{2},{3}", "a", , 9.2, DateTime.Now); // a,1,9.2,2018/2/3 22:39:52
Console.WriteLine(result);
.Net转Java.08.format的更多相关文章
- java.time.format.DateTimeFormatter
Java的日期与时间 DateTimeFormatter类是Java 8中日期时间功能里,用于解析和格式化日期时间的类,位于java.time.format包下. 1.预定义的DateTimeFo ...
- JAVA Stirng.format 使用理解
JAVA Stirng.format 使用理解前言:项目中需要对一些字符串处理发现format方法的神奇之处一.api才是王道第一种二参使用①public static String format(S ...
- java.time.format.DateTimeParseException: Text '2019-10-11 12:30:30' could not be parsed at index 10
java.time.format.DateTimeParseException: Text '2019-10-11 12:30:30' could not be parsed at index 10 ...
- fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:11' could not be parsed at index 10
本地java类 import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; ...
- java String.Format详解
JDK1.5中,String类新增了一个很有用的静态方法String.format(): format(Locale l, String format, Object... args) 使用指定的语言 ...
- JAVA String.format 方法使用介绍
1.对整数进行格式化:%[index$][标识][最小宽度]转换方式 我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...
- JAVA String.format 方法使用介绍<转>
在JDK1.5中,String类增加了一个非常有用的静态函数format(String format, Objece... argues),可以将各类数据格式化为字符串并输出.其中format参数 ...
- java MessageFormat.format 用法
FormatElement: { ArgumentIndex }:是从0开始的入参位置索引. { ArgumentIndex , FormatType } { ArgumentIndex , Form ...
- Java String.Format() 方法及参数说明
转自:https://blueram.iteye.com/blog/441683 JDK1.5中,String类新增了一个很有用的静态方法String.format():format(Locale l ...
随机推荐
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-1目录
Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了 Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Ne ...
- Zepto的使用以及注意事项
为什么选择Zepto.js的原因: zepto.js的语法借鉴并且兼容jQuery,会使用jquery就会使用Zepto.js.Zepto.js是移动端的js库.Zepto.js相当于PC端的j ...
- js下拉列表
js清除下拉列表所选默认值 $("#lineId").val(“”); js清除下拉列表所有选项 $("#type").html(""); ...
- Qt错误 —— 无法启动此程序 因为计算机丢失QtCore5.dll 以及 无法定位程序输入点于动态链接库QtCore5.dll
首先,设置计算机的环境变量Path,计算机=>右键属性=>高级设置=>环境变量=>系统变量=>双击Path,在Path后面增加C:\Qt\Qt5.8.0\5.8\ming ...
- SQL语句中单引号、双引号和反引号的区分
反引号 反引号:反引号一般在Esc键的下方,为了区分MySQL的保留字与普通字符而引入的符号. 一般我们建表时都会将表名,库名都加上反引号来保证语句的执行度. 例如: SELECT * FROM `u ...
- 【基础】链表的储存结构说明(python)
[实现链表的添加] class aNode(): def __init__(self,data=None,nxt=None): self.data=data self.nxt=nxt class ru ...
- 我与Vuex的第一次邂逅
new Vue({ // state data () { return { count: 0 } }, // view template: ` <div>{{ count }}</d ...
- 自己总结的C#编码规范--6.格式篇
格式 格式的统一使用可以使代码清晰.美观.方便阅读.为了不影响编码效率,在此只作如下规定: 长度 一个文件最好不要超过500行(除IDE自动生成的类). 一个文件必须只有一个命名空间,严禁将多个命名空 ...
- 如何安装使用FastReport
1.百度搜索FastReport.Net4.0下载,或者到我的云盘去下载. 2.解压后打开目录:FastReport.Net4.0_Full.安装:FRNetDemo2010.msi 3.把FastR ...
- excel计算时间差值
excel计算时间差值 2018/10/1 10:59:00 减去 2018/9/21 1:05:13 获取 多少天. 如1.2天.这种. ==