如題,我先將它轉換為NSString然後移除(),但是換行還是顯示。
NSString *myArrayString = [self.selectedStates description];
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()\n\""];
myArrayString = [myArrayString stringByTrimmingCharactersInSet:charsToTrim];
輸出如下:
1,
2,
3,
4,
5,
6
實際上我需要實現的輸出是這樣的:
1,2,4,5,6
依賴description
不是最好的方法,試試這樣。
NSString *desc = [theArray componentsJoinedByString:@","];
還可以使用你的方法:
NSString *desc = [[theArray description] stringByReplacingOccurrencesOfString:@"\n" withString:@""];