格式化字符串的String.Format(" {0:00}" [英] Formatting a string with string.Format("{0:00}"

查看:957
本文介绍了格式化字符串的String.Format(" {0:00}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚接手一些code,我看到这个用了很多。它似乎采取整数和创建字符串看起来像01,02等

什么我不知道的是这里使用的约定。为什么格式 {0:00} ,而不是 {00}

 的String.Format({} 0:00,int.Parse(名为testVal)+ 1);
 

解决方案

第一个 0 是占位符,表示第一个参数。 00 是一个实际的格式。

例如它可以是这样的:

  VAR的结果=的String.Format({0:00}  -  {} 1:00,5,6);
 

结果 05 - 06 。因此,第一个0手段采取的第一个参数5,而1手段,采取参数6。

格式为 {索引[,长度] [:formatString中]} 。看看的String.Format方法

I have just taken over some code and I see this used a lot. It seems to take the integer and create a string looking like "01", "02" etc.

What I am not sure of is the convention used here. Why is the format {0:00} and not {00}?

string.Format("{0:00}", int.Parse(testVal) + 1);

解决方案

The first 0 is the placeholder, means the first parameter. 00 is an actual format.

For example it could be like this:

var result = string.Format("{0:00} - {1:00}", 5, 6);

result will be 05 - 06. So the first 0 is means take the first parameter 5, while 1 means to take parameter 6.

The format is {index[,length][:formatString]}. Take a look at String.Format Method.

这篇关于格式化字符串的String.Format(" {0:00}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆