格式字符串,前导零的整数 [英] Format string, integer with leading zeros

查看:112
本文介绍了格式字符串,前导零的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这段代码:

  NSString * strName = [NSString stringWithFormat:@img_00%d.jpg,pp ]。 

可以正常工作,但是如果pp取10的值,我希望将img_010.jpg作为结果,而不是img_0010.jpg ...
如何格式化字符串??
$ b

谢谢

解决方案

使用格式字符串img_%03d.jpg来获取三位数和前导零的十进制数。 p>

I Use this code:

NSString* strName = [NSString stringWithFormat:@"img_00%d.jpg", pp];

and works fine, but if pp took the value of 10 for example I wish have img_010.jpg as result, and not img_0010.jpg... how can I format the string??

thanks

解决方案

Use the format string "img_%03d.jpg" to get decimal numbers with three digits and leading zeros.

这篇关于格式字符串,前导零的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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