<分区>
标签 ios objective-c
<分区>
如何以 number$sound 格式返回附加字符串,然后在返回时将字符串再次分成两部分,如 objective-c 中的(数字和声音文件名)
最佳答案
整数版本:
int number = 10;
NSString *sound = @"sound";
NSString *combinedString =
[sound stringByAppendingString:
[NSString stringWithFormat:@"%d$%@",number,sound]];
字符串版本:
NSString *number = @"10";
NSString *sound = @"sound";
NSString *combinedString =
[sound stringByAppendingString:
[NSString stringWithFormat:@"%@$%@",number,sound]];
输出:10$声音
NSArray *combinedObjects = [combinedString componentsSeparatedByString:@"$"];
NSString *mynumber=[combinedObjects objectAtIndex:0];//10
NSString *mysound= [combinedObjects objectAtIndex:1];//sound
关于ios - 在 ios 中附加格式如数字和声音的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247802/