如何以数字$ sound的格式返回附加的字符串,然后当它返回时,将字符串分解为两个部分,如objective-c中的(数字和声音文件名)
答案 0 :(得分:1)
整数版:
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
答案 1 :(得分:0)
将NSString
与$
NSArray* separatedString = [yourString componentsSeparatedByString:@"$"];