c# – 掩码将格式化为1,10,100,到字符串“001”,“010”,“100”
发布时间:2020-12-15 03:56:51 所属栏目:百科 来源:网络整理
导读:如何将掩码应用于以下列方式格式化输出文本的字符串(最多2个前导零): int a = 1,b = 10,c = 100;string aF = LeadingZeroFormat(a),bF = LeadingZeroFormat(b),cF = LeadingZeroFormat(c);Console.Writeline("{0},{1},{2}",aF,bF,cF); // "001,010,100" 什
如何将掩码应用于以下列方式格式化输出文本的字符串(最多2个前导零):
int a = 1,b = 10,c = 100; string aF = LeadingZeroFormat(a),bF = LeadingZeroFormat(b),cF = LeadingZeroFormat(c); Console.Writeline("{0},{1},{2}",aF,bF,cF); // "001,010,100" 什么是最优雅的解决方案? 提前致谢. 解决方法
您可以使用Int32.ToString(“000”)以此方式格式化整数.详情请参阅
Custom Numeric Format Strings和
Int32.ToString:
string one = a.ToString("000"); // 001 string two = b.ToString("000"); // 010 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |