String.Format()方法
String.Format方法是我们在.Net应用开发时经常使用到的,它的灵活使用有时能够达到事半功倍的效果,下面我们就借用MSDN上的一个示例来向大家展示String.Format的各种用法。
// This code example demonstrates the String.Format() method.
using System;
class Sample
...{
enum Color ...{Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
...{
// Store the output of the String.Format method in a string.
string s = "";
// Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers");
s = String.Format(
"(C) Currency: . . . . . . . . {0:C} " +
"(D) Decimal:. . . . . . . . . {0:D} " +
"(E) Scientific: . . . . . . . {1:E} " +
"(F) Fixed point:. . . . . . . {1:F} " +
"(G) General:. . . . . . . . . {0:G} " +
" (default):. . . . . . . . {0} (default = 'G') " +
"(N) Number: . . . . . . . . . {0:N} " +
"(P) Percent:. . . . . . . . . {1:P} " +
"(R) Round-trip: . . . . . . . {1:R} " +
"(X) Hexadecimal:. . . . . . . {0:X} ",
-123, -123.45f);
Console.WriteLine(s);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
s = String.Format(
"(d) Short date: . . . . . . . {0:d} " +
"(D) Long date:. . . . . . . . {0:D} " +
"(t) Short time: . . . . . . . {0:t} " +
"(T) Long time:. . . . . . . . {0:T} " +
"(f) Full date/short time: . . {0:f} " +
"(F) Full date/long time:. . . {0:F} " +
"(g) General date/short time:. {0:g} " +
"(G) General date/long time: . {0:G} " +
" (default):. . . . . . . . {0} (default = 'G') " +
"(M) Month:. . . . . . . . . . {0:M} " +
"(R) RFC1123:. . . . . . . . . {0:R} " +
"(s) Sortable: . . . . . . . . {0:s} " +
"(u) Universal sortable: . . . {0:u} (invariant) " +
"(U) Universal sortable: . . . {0:U} " +
"(Y) Year: . . . . . . . . . . {0:Y} ",
thisDate);
Console.WriteLine(s);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
s = String.Format(
"(G) General:. . . . . . . . . {0:G} " +
" (default):. . . . . . . . {0} (default = 'G') " +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer) " +
"(D) Decimal number: . . . . . {0:D} " +
"(X) Hexadecimal:. . . . . . . {0:X} ",
Color.Green);
Console.WriteLine(s);
}
}
String.Format()方法相关推荐
- String.format()方法使用说明
2019独角兽企业重金招聘Python工程师标准>>> JDK1.5开始String类中提供了一个非常有用的方法String.format(String format, Object ...
- String.format()方法的使用
转载自 java字符串格式化:String.format()方法的使用 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的读者应该记得C ...
- String.format() 方法用法解说
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. String chargeFlowUrl = _AGENT_URL+ "?agentAcc ...
- Objective-C 字符串拼接函数 多个不同类型的参数拼接到一个字符串 类似于Java中 String.format()方法的原生API
总目录 iOS开发笔记目录 从一无所知到入门 文章目录 需求 Screenshot Code Output 需求 我有多个参数(类型也许不同),需要拼接到一个字符串中. 在Java中有String.f ...
- java百分号的用法,Java String.format()方法中使用百分号'%'_栗子教程
下面这个例子演示了如何在String.format方法中显示一个百分号. 像下面这样直接调用String.format("%d%", 100)来显示百分号,将会抛出java.uti ...
- String.format()方法详解
String.format()方法详解 前言: String.format()作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,这里根据查阅的资料做个学习笔记,整理成如下文章,供后续复习查阅. ...
- JAVA String.format 方法使用介绍
在JDK1.5中,String类增加了静态方法format(String format, Objects... args),format(Local l ,String format, Objects ...
- JAVA String format 方法使用介绍
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 在JDK ...
- java字符串格式化:String.format()方法的使用
String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的读者应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. l ...
最新文章
- python上机实验报告读取文件_Python程序设计实验报告八 : 文件
- python如何导入txt文件-数据从txt文本导入python
- VC采集网页所有表单域
- C# UI界面的更新
- html按钮坐标,html-单选按钮位置CSS
- 字体大宝库:设计师必备的专业免费英文字体
- Python调用微博API获取微博内容
- 理论 | 教你彻底学会Java序列化和反序列化
- 政治经济学第一-三章脉络图
- tomcat启动war包_不用下载tomcat,maven插件直接运行war包,真香
- 自动化通讯协定——现场总线
- CCF NOI1005 存款收益
- 多种问题袭来:崩溃在边缘的“直播赚钱路”
- Python 快速验证代理IP是否有效
- 【bb平台刷课记】wireshark结合实例学抓包
- swagger设置字段required必填
- 高德地图获取坐标距离_计算两个坐标点之间的距离(高德地图)
- Flume+kafka+Spark Steaming demo2
- 3d建模网上学习靠谱吗?学3d建模哪个大学好?
- 私域运营中引流加爆微信好友的方法
热门文章
- mysql 脑裂的问题,DRBD脑裂问题故障处理
- Python Qt GUI设计:QTableView、QListView、QListWidet、QTableWidget、QTreeWidget和QTreeWidgetltem表格和树类(提升篇—1)
- Python Qt GUI设计:QLabel标签类(基础篇—11)
- LabVIEW仪表盘识别(实战篇—6)
- TinkerNode NB-IoT物联网开发板(NB-IoT专栏—拓展篇3)
- Keil5简介、下载及安装(NB-IoT专栏—基础篇2)
- Linux 内核启动流程
- P2P Device Discovery流程分析
- sysfs_create_dir_ns
- 【深度学习】(5) 简单网络,案例:服装图片分类,附python完整代码