我從服務器URL獲取的結果放到數組中,數組中放了星期對象,但是在獲取的時候會得到逗號,我想刪除這些逗號然後可以比較。不知道應該怎麼做?
array3:
(
{
Code = "Sunday,";
},
{
Code = "Thursday,";
},
{
Code = "Friday,";
},
{
Code = "Saturday,";
}
)
比較:
NSMutableArray *yourArray = [[NSMutableArray alloc] init];
for (NSDictionary *dict in array3) {
[yourArray addObject:[dict valueForKey:@"Code"]];
}
BOOL isTheObjectThere = [yourArray containsObject:@"Thursday"];
但是系統會報出isTheObjectThere 'NO' 錯誤因為得到數組如下:
(
Sunday,,
Thursday,,
Friday,,
Saturday,
)
試試:
for (NSDictionary *dict in array3) {
NSString *str=[dict valueForKey:@"Code"];
NSString*newstr= [str stringByReplacingOccurrencesOfString:@"," withString:@""];
[yourArray addObject:newstr];
}