2010-09-27 128 views
0
NSArray *ArtistNames = [RawData componentsMatchedByRegex:regEx1]; 
    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"'"]; 
    ArtistNames = [[ArtistNames componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @"'"]; 

這就是我的代碼在這一刻基本上我不能使用它作爲ArtistNames是一個數組而不是一個字符串,我會如何過去呢?替換數組中的字符串

回答

7

我想你是按錯誤的順序調用你的方法。嘗試將其分解爲多個語句。

// The separator should be some string of characters guaranteed to not be in any of the strings in the array. 
#define SEPARATOR @"---***---" 

NSArray *artistNames = [RawData componentsMatchedByRegex:regEx1]; 
NSString *doNotWant = @"'" 
NSString *combinedNames = [artistNames componentsJoinedByString:SEPARATOR]; 
combinedNames = [combinedNames stringByReplacingOccurrencesOfString:doNotWant withString:@""]; 
artistNames = [combinedNames componentsSeparatedByString:SEPARATOR]; 
+0

SEPARATOR?對不起,我對這個對象很陌生c – user393273 2010-09-27 19:37:22

+0

我修好了謝謝你,我用@替換了SEPARATOR,「感謝感謝」 – user393273 2010-09-27 19:39:27

+0

「NSString * doNotWant ...」:-) – 2010-09-27 20:43:03

1

爲什麼不簡單地遍歷數組並自己創建第二個數組?