从字符串分割到数组- componentsSeparatedByString:
NSString *string = [[NSString alloc] initWithString:@"One,Two,Three,Four"];
NSLog(@"string:%@",string);
NSArray *array = [string componentsSeparatedByString:@","];
NSLog(@"array:%@",array);
[string release];
結果呈現
2012-06-15 17:10:34.028 Hotairballoon[546:707] string:One,Two,Three,Four
2012-06-15 17:10:34.029 Hotairballoon[546:707] array:(
One,
Two,
Three,
Four
)
从数组合并元素到字符串- componentsJoinedByString:
NSArray *array = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four",nil];
NSString *string = [array componentsJoinedByString:@","];
NSLog(@"string:%@",string);
結果呈現
2012-06-15 17:16:57.596 Hotairballoon[565:707] string:One,Two,Three,Four
沒有留言:
張貼留言