2010-09-27 155 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

为什么不简单地遍历数组并自己创建第二个数组?