Conversion of iOS array and string

1. Convert a string to an array

NSString *string = @"a,b,c,d";
NSArray  *array = [string componentsSeparatedByString:@","];

2. Convert the array to a string

NSArray *array = @[@"a",@"b",@"c",@"d"];
NSString *string = [array componentsJoinedByString:@","];

The mutual conversion depends on what symbol is used to separate the elements, and what symbol is used for splicing. The commas "and" above   can also be replaced by dots "  ." Or comma "and"

Guess you like

Origin blog.csdn.net/zjpjay/article/details/90230959