iphone - 来自字符串数组 iPhone 的子字符串

标签 iphone objective-c ios

我有一个数组,见下文,

NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];      

现在我想要将字符“x”右边的所有字符串放入另一个数组中。那就是我需要一个包含上述数组中的元素 @"2",@"3",@"3" 的数组。

我怎样才能做到这一点?? 谢谢..

最佳答案

NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];
NSMutableArray *tempArray = [NSMutableArray array];
for(NSString *string in myArray)
{
    NSArray *array = [string componentsSeparatedByString:@"x"];
    if(array.count > 1)
        [tempArray addObject:[array objectAtIndex:1]];
}

关于iphone - 来自字符串数组 iPhone 的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283064/

相关文章:

iphone - UITextView 隐藏一些文本

swift - 如何通过代码在 SceneKit 中设置基于物理的渲染?

ios - 谷歌地图热图颜色按平均重量

iphone - 平铺作为纹理图集一部分的图像

iphone - 未显式调用 Objective-C 版本

ios - Objective-C内存管理:什么时候使用`[variable release]`vs`variable = nil`来清理内存?

ios - GPUImage 相机打不开

ios - 解析122错误上传

ios - 在我的应用程序中从客户向另一个客户付款使用 paypal 还是 stripe?

iphone - 如何更改 slider 缩略图?