NSMutableArray转换为NSString

时间:2013-01-21 11:17:02

标签: objective-c nsmutablearray

这是来自NSMutableArray的字符串:

(
    (
        "Some String Value"
    )
)

此代码显示我想要的字符串值,但是,它会显示括号和引号。我该如何删除它们?

提前谢谢!!

2 个答案:

答案 0 :(得分:1)

在您的情况下,它是2D数组:

这样的事情:

NSArray *arr=[NSArray arrayWithObject:@"asdf"];
NSArray *arr2=[NSArray arrayWithObjects:arr, nil];

你需要进入第二级才能将其恢复为:

NSLog(@"=> %@",arr2[0][0]);
NSString *string=arr2[0][0];

答案 1 :(得分:0)

- (void)repeatArray:(NSArray *)array1 {

static NSMutableString *InsideString; // Better to use global Varaible declared in ViewDidLoad/loadView

NSArray *array = array1; //Its your array

for (int i = 0; i< [array count]; i++) {
    if ([[array objectAtIndex:i] isKindOfClass:[NSArray class]]) {
        [self repeatArray:[array objectAtIndex:i]];
    } else if ([[array objectAtIndex:i] isKindOfClass:[NSString class]]) {
        [InsideString appendString:[NSString stringWithFormat:@"%@ ", [array objectAtIndex:i]]];
    }
}

}