String format(String format, Object... args)

The format specifiers for general, character, and numeric types have the following syntax:

%[argument_index$][flags][width][.precision]conversion
  • argument_index is a decimal integer indicating the position of the argument in the argument list. It starts from "1$".
  • flags is a set of  characters that modify the output format.
Flag General Character Integer Floating Point Date/Time Description
'-' Y Y Y Y Y The result will be left-justified
'#' Y - Y Y - The result should use a conversion-dependent alternate form
'+' - - Y Y - The result will always include a sign
' '  - - Y Y - The result will include a leading space for positive values
'0' - - Y Y - The result will be zero-padded 
',' - - Y Y - The result will include locale-specific grouping separators 
'(' - - Y Y - The result will enclose negative numbers in parentheses 
  • width is a non-negative decimal interger indicating the minimum number of the number of characters to be written to the output.
  • For the floating-point conversions 'e''E', and 'f' the precision is the number of digits after the decimal separator. If the conversion is 'g' or 'G', then the precision is the total number of digits in the resulting magnitude after rounding. If the conversion is 'a' or 'A', then the precision must not be specified.
  • conversion are divided into the following categories:

    General, Character, Numeric(Integer, Floating Point), Date/Time, Percent, Line Separator

Conversion Argument Category Description
'b''B' general If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".
'h''H' general If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()).
's''S' general If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invokingarg.toString().
'c''C' character The result is a Unicode character
'd' integral The result is formatted as a decimal integer
'o' integral The result is formatted as an octal integer
'x''X' integral The result is formatted as a hexadecimal integer
'e''E' floating point The result is formatted as a decimal number in computerized scientific notation
'f' floating point The result is formatted as a decimal number
'g''G' floating point The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding.
'a''A' floating point The result is formatted as a hexadecimal floating-point number with a significand and an exponent
't''T' date/time Prefix for date and time conversion characters. See Date/Time Conversions.
'%' percent The result is a literal '%' ('\u0025')
'n' line separator The result is the platform-specific line separator

String.format Tutorial的更多相关文章

  1. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  2. 【转】string.Format对C#字符串格式化

    转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...

  3. C#中string.format用法详解

    C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...

  4. string.Format格式化用法详解

    1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...

  5. Js实现string.format

    经常需要动态拼接html字符串,想到用类似于.net的string.format函数比较好,于是找了下,stackoverflow的代码: if (!String.prototype.format) ...

  6. String.Format用法

    http://blog.csdn.net/yohop/article/details/2534907 1.作为参数   名称 说明   Format(String, Object) 将指定的 Stri ...

  7. String.Format 格式说明

    C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...

  8. C# String.Format格式化json字符串中包含"{" "}"报错问题

    json.Append(String.Format("{\"total\":{0},\"row\":{1}}", lineCount, st ...

  9. JAVA字符串格式化-String.format()的使用

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...

随机推荐

  1. OpenGL ES 2.0 曲面物体的构建

    球体构建的基本原理构建曲面物体最重要的就是找到将曲面恰当拆分成三角形的策略. 最基本的策略是首先按照一定的规则将物体按行和列两个方向进行拆分,这时就可以得到很多的小四边形.然后再将每个小四边形拆分成两 ...

  2. C++新式类型转换

    C++的四种强制类型转换,所以C++不是类型安全的.分别为:static_cast , dynamic_cast , const_cast , reinterpret_cast 新类型的强制转换可以提 ...

  3. 自动化测试CTS命令

    #!/sbin/sh chmod +x /system/bin/input i=0 while [ "$i" != "10" ] do #am instrume ...

  4. 调查程序phpquestionnaire 2.2中文安装注意

    最近找调查投票软件 找到limesurvey 和 phpquestionnaire,limesurvey 中文可以用,但是比较烦琐.phpquestionnaire有汉化过的包下载,但是安装完,发现中 ...

  5. destoon控制标题长度,title中显示全标题 标题字符长度怎么控制?

    如题商品调用出来后,标题的字符长度怎么控制?有哪位高手能帮我解决吗? 小弟在此感谢了. &length=30 //30表示30个字节 <!--{tag("moduleid=5& ...

  6. [php] PHP创建指定目录和文件

    前几天看到有人问PHP环境下如何创建文件到指定目录下,正好自己最近在学习,经过一翻测试,终于出结果了,贴出来与大家分享. 目录结构: 代码所在的文件wwwroot/mydir/test/test.ph ...

  7. hdu 2034

    Problem Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法 ...

  8. 一次处理ORA-07445的历险记(转)

    ORA-07445通常是Oracle调用操作系统的资源出错时出现的[@more@] 事前没有任何征兆,下午5点左右某个关键应用的17台oracle数据库上的数据库实例陆续宕机,赶紧查看alert_lo ...

  9. The Most Wanted Letter

    The Most Wanted Letter You are given a text, which contains different english letters and punctuatio ...

  10. Android基础之退出应用程序Demo

    对于Android我也不是很熟悉,只是学习一些基本内容就OK.所以写的内容也很简单.本Demo要实现的效果就是双击返回键弹出提示框确认是否退出程序. 一.废话少说直接上代码.至于涉及到的相关包在Ecl ...