有兩個用逗號分開的NSString
,我想要移除第一個字符重復的字符。
ex. str1 = 0,1,2,3
str2 = 1,2.
output -> str1 = 0,3 and str2 = 1,2.
有一種辦法是,用逗號分開兩個字符串,但是需要兩個NSArray和LOOP循環,然後移除評論元素,但是這樣實現起來非常困難,有沒有簡單辦法實現?謝謝好心人幫忙。
可以不用循環
但是需要設置好所有的API
NSString *str1=@"0,1,2,3";
NSString *str2=@"1,2";
NSMutableArray *arr1=[[NSMutableArray alloc]initWithArray:[str1 componentsSeparatedByString:@","]];
[arr1 removeObjectsInArray:[str2 componentsSeparatedByString:@","]];
NSLog(@"arr1 %@",arr1);
/*
NSMutableString *finalString=[NSMutableString new];
for (NSInteger i=0; i<[arr1 count]; i++) {
NSString *str=[arr1 objectAtIndex:i];
[finalString appendString:str];
if (i!=[arr1 count]-1) {
[finalString appendString:@","];
}
}
*/
NSString *finalString=[arr1 componentsJoinedByString:@","];
NSLog(@"finalString %@",finalString);