ios - 在 ios 中附加格式如数字和声音的字符串

标签 ios objective-c

<分区>


这个问题似乎离题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a minimal example在问题本身。

关闭 8 年前

如何以 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/

上一篇:ios - MVVMCross 绑定(bind)属性在 iOS 模拟器中工作正常,但在设备上失败

下一篇:android - 在 Chartboost 中隐藏插页式广告

相关文章:

ios - 导航栏后退按钮只能使用一次

ios - 让图像沿着 x 轴跟随您的手指,但具有固定的 y 坐标

ios - 如何在 OpenGL 中绘制点的轮廓?

ios - 如何在导航栏内实现搜索栏分段控制?

ios - [NSDateFormatter 类] : message sent to deallocated instance

ios - 如何获取通过 iphone 中的照片库选择的图像的名称?

ios - 我的 viewDidAppear 未在 View Controller 中调用

ios - TableView 单元格属性保持为零

ios - 有没有办法使用 Objective C 从 iOS 中的另一个应用程序访问一个应用程序的数据库?

IOS预期表达式错误