jjzjj

LeadingZeroFormat

全部标签

c# - 将 int 1、10、100 格式化为字符串 "001"、 "010"、 "100"的掩码

我如何将掩码应用于字符串以按以下方式格式化输出文本(最多2个前导零):inta=1,b=10,c=100;stringaF=LeadingZeroFormat(a),bF=LeadingZeroFormat(b),cF=LeadingZeroFormat(c);Console.Writeline("{0},{1},{2}",aF,bF,cF);//"001,010,100"什么是最优雅的解决方案?提前致谢。 最佳答案 您可以使用Int32.ToString("000")以这种方式格式化整数。有关详细信息,请参阅CustomNumer