开发者

Replace string within a array

开发者 https://www.devze.com 2023-01-18 00:12 出处:网络
NSArray *ArtistNames = [RawData componentsMatchedByRegex:regEx1]; NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@\"'\"];
    NSArray *ArtistNames = [RawData componentsMatchedByRegex:regEx1]; 
    NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"'"];
    ArtistNames = [[ArtistNames co开发者_StackOverflow社区mponentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @"'"];

Thats my code at the moment basically i cannot use it as ArtistNames is a array not a string, how would i get past this ?


I think you're calling your methods in the wrong order. Try breaking it into multiple statements.

// 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];


Why not just loop over the array and create the second array yourself?

0

精彩评论

暂无评论...
验证码 换一张
取 消