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. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  3. 用U盘烧写Uboot.bin到Nor Flash

    1.在开发板上面插上U盘 2.打到 NAND flash模式启动U-boot,输入以下命令打开usb设备. [u-boot@SMDK2440A]# usb reset //以重启的方式 或者用 [u- ...

  4. jquery uploadify插件多文件上传

    1.jquery uploadify 下载:http://www.uploadify.com/ 2.安装:解压后拷贝的工程目录下面,如:WebRoot/uploaddify 3.配置项说明: uplo ...

  5. Kendo Web UI Grid数据绑定,删除,编辑,并把默认英文改成中文

    Kendo Web UI 是个不错的Jquery框.可惜老外写的,很多都是默认的英文,当然我们也可以设置成中文,接下来,我们就看看Grid是如何实现的数据绑定(Kendo Grid数据绑定实现有很多方 ...

  6. PHP内置Web Server探究(一)启动Cli_Server

    自PHP5.4之后 PHP内置了一个Web 服务器(cli_server),类似于Python的内置server一样,方便我们开发阶段的调试 主要使用场景: 1,没有搭建nginx或apache等第三 ...

  7. POJ1722 动态规划

    POJ1722 问题重述: 给定一个数组a[1,2,..,n] .定义数组第i位上的减操作:把ai和ai+1换成ai - ai+1.输入一个n位数组以及目标整数t,求一个n-1次操作序列,使得最后剩下 ...

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

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

  9. php 实时推送代码

    网站质量不错的网站可以在百度站长平台/数据提交/sitemap栏目下看到实时推送的功能, 目前这个工具是邀请开放, 百度的实时推送的api接口可以实时推送我们新发布的文章, 保证百度在第一时间收录. ...

  10. 计算textView的高度

    - (CGFloat)measureHeightOfUITextView:(UITextView *)textView { if (floor(NSFoundationVersionNumber) & ...