将int表示为字符串 [英] represent int as string

查看:68
本文介绍了将int表示为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个表示为字符串的int值来表示小时和分钟。如果我得分为0我必须表示为00 ..请帮助

Hi,

I have a int value represented as string to represent hour and minute. If i get minute as 0 i must represent as 00.. pls help

推荐答案

尝试

Try
string formatted = string.Format("{0:D2}", 0);

指定的D表示你想要一个固定大小的整数,2表示至少两位数,如果需要,使用前导零

http://msdn.microsoft.com/en-gb/library/dwhawy9k.aspx [ ^ ]

The "D" specified indicates you want a fixed size integer, the 2 says "a minimum of two digits, use leading zeros if needed"
http://msdn.microsoft.com/en-gb/library/dwhawy9k.aspx[^]


假设您的意思是Visual Studio和.Net,请查看 String.Format [ ^ ]
Assuming you mean Visual Studio and .Net, have a look at String.Format[^]


这篇关于将int表示为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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