开发者

Objective-C string formatting [duplicate]

开发者 https://www.devze.com 2023-03-31 17:34 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicates: Format string, integer with leading zeros
This question already has answers here: Closed 11 years ago.

Possible Duplicates:

Format string, integer with leading zeros

String Formatting Tricks/Docs

I have a really simple question but didn´t find document about.

I am using this code :

开发者_StackOverflow
NSString *fileName = [NSString stringWithFormat:@"0%i.mp3", i];

so the @"0%i.mp3" = 01.mp3, 02.mp3 ... 09.mp3 files

My issue is I have this mp3 with a longer name like 01-thefirstsong.mp3 , 02-mysecondsong.mp3 ... 15-mylastsong.mp3

How can I write this like @"allmyfiles.mp3" ?

Regards


If you use this

int i = 1;
NSString *name = @"thefirstsong";
NSString *filename = [NSString stringWithFormat:@"%0d-%@.mp3", i, name];

filename will contain 01-thefirstsong.mp3.

%@ is the placeholder for objectiveC strings (NSString).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号