在ios中添加一个格式为数字和声音的字符串

时间:2014-03-07 10:40:07

标签: ios objective-c

如何以数字$ sound的格式返回附加的字符串,然后当它返回时,将字符串分解为两个部分,如objective-c中的(数字和声音文件名)

2 个答案:

答案 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:@"$"];