How to convert elements of NSMutableArray to NSString

前端 未结 3 1166
广开言路
广开言路 2021-01-21 15:05

I have 1 NSMutableArray and I want to convert whatever data in array will be in NSString. tell me code for that. Array is nothing but object of NSMutableArray class.

3条回答
  •  清歌不尽
    2021-01-21 15:43

    It depends on how you want your string. One approach could be iterate through array and convert each element of it.

    NSMutableString * result = [[NSMutableString alloc] init];
    for (NSObject * obj in array)
    {
        [result appendString:[obj description]];
    }
    NSLog(@"The concatenated string is %@", result);
    

    You can modify the above code based on item's class.

    Below code will convert Array to string with commas and other information.

    NSString * result = [array description];
    

提交回复
热议问题