格式化我的字符串
如何格式化这样的字符串:
string X = "'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",????
我记得我曾经能够在末尾放置一个逗号并指定要分配给 {0}、{1} 等的实际数据。
有任何帮助吗?
How can I format a string like this:
string X = "'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}'",????
I remember I used to be able to put a comma at the end and specify the actual data to assign to {0},{1}, etc.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您是否在寻找:
将导致
“带有数据 Foo 的字符串,我希望格式化的 Bar”
are you looking for:
would result in
"String with data Foo, Bar I wish to format"
使用
string.Format
如Use
string.Format
as in使用 string.Format 方法,例如:
Use string.Format method such as in:
如果您有字符串数组中的值,另一种方法是使用 Join:(
只是想与 89724362 用户不同,他们将向您展示如何使用 String.Format...;)
An alternative is to use Join, if you have the values in a string array:
(Just wanted to be different from the 89724362 users who will show you how to use String.Format... ;)
String.Format
方法接受一个格式字符串,后跟一对要格式化的变量。格式字符串由占位符组成,这些占位符本质上是放置传递给函数的变量值的位置。The
String.Format
method accepts a format string followed by one to many variables that are to be formatted. The format string consists of placeholders, which are essentially locations to place the value of the variables you pass into the function.你的问题有点含糊,但你的意思是:
还是你在要求别的东西?
Your question is a bit vague, but do you mean:
Or are you asking for something else?
使用 string.format,并将单独的格式说明符放在大括号内,在数字和冒号之后,如
and 所示,正如您从示例中看到的,您不需要单引号来描述文字,任何不在大括号内的内容都会按字面意思输出
use string.format, and put individual format specifiers inside the braces, after the number and a colon, as in
and, as you can see from the example, you don;t need the single quotes to delineate literals, anything not inside braces will be output literally