String.format Tutorial
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的更多相关文章
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- 【转】string.Format对C#字符串格式化
转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...
- C#中string.format用法详解
C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...
- string.Format格式化用法详解
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
- Js实现string.format
经常需要动态拼接html字符串,想到用类似于.net的string.format函数比较好,于是找了下,stackoverflow的代码: if (!String.prototype.format) ...
- String.Format用法
http://blog.csdn.net/yohop/article/details/2534907 1.作为参数 名称 说明 Format(String, Object) 将指定的 Stri ...
- String.Format 格式说明
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...
- C# String.Format格式化json字符串中包含"{" "}"报错问题
json.Append(String.Format("{\"total\":{0},\"row\":{1}}", lineCount, st ...
- JAVA字符串格式化-String.format()的使用
String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...
随机推荐
- OpenGL ES 2.0 雾
在场景中使用雾不但可以提高真实感,特定的情况下还能优化性能.具体是指当物体离摄像机足够远时,雾就足够浓,此时只能看到雾而看不到物体,也就不必对物体着色进行详细计算,这样可以大大提高渲染效率. 雾有很多 ...
- poj 2479 dp求分段最大和
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38079 Accepted: 11904 Des ...
- Tornado 模板支持“控制语句”和“表达语句”的表现形式
Tornado 的模板支持“控制语句”和“表达语句”,控制语句是使用 {% 和 %} 包起来的 例如 {% if len(items) > 2 %}.表达语句是使用 {{ 和 }} 包起来的,例 ...
- set用法总结
set集合用于存放不重复的元素 template <class Key, class Compare = less<Key>, class Alloc = alloc> cla ...
- JQuery实现倒计时效果
首先:引入jquery文件 <script type="text/javascript" src="http://www.cnblogs.com/Content/P ...
- php中的MVC模式运用
[size=5][color=Red]php中的MVC模式运用[/color][/size] 首先我来举个例子: 一个简单的文章显示系统 简单期间,我们假定这个文章系统是只读的,也就是说这个例子将不涉 ...
- Lambda表达式 之 C#
Lambda表达式 "Lambda表达式"是一个匿名函数,是一种高效的类似于函数式编程的表达式,Lambda简化了开发中需要编写的代码量.它可以包含表达式和语句,并且可用于创建委托 ...
- key转成pvf
https://www.godaddy.com/help/converting-an-exported-pfx-code-signing-file-to-pvk-and-spc-files-using ...
- Windows资源文件里VarFileInfo的Translation(EXE的语言描述信息)
/* The following line should only be modified for localized versions. */ /* It consists of any numbe ...
- 设置EntityFramework 在开发时自动更新数据库
1. NuGet 下载EntityFramework. 2. 定义Context 和 打开NuGet 命令 执行 Enable-Migrations , Libaray.DAL.Migrations. ...