Abstract Text Example and Question
Abstract Text Example and Question
- Subject: Abstract Text Example and Question
- From: Brad Stone <email@hidden>
- Date: Wed, 9 Feb 2011 22:04:58 -0500
I made this code to remove any duplicate words from a large group of text. The result is stored in an index file so the text doesn't need to make sense. I'm removing the duplicates to save space in the index file. I was wondering if anyone had a suggestion for a more efficient way to accomplishing this. I'm guessing the separations and joins are taking up memory and slowing things down (even though I'm not positive about that). Using this code reduced the index file size form 4.7MB to 2.7MB.
Thanks
- (NSString *)abstractText:(NSString *)srcString {
NSMutableArray *resultArray = [[NSMutableArray alloc] init];
NSArray *textArray = [srcString componentsSeparatedByString:@" "];
for (NSString *s in textArray) {
s = [s stringByTrimmingCharactersInSet:[NSCharacterSet alphanumericCharacterSet]];
s = [s lowercaseString];
if ([resultArray indexOfObject:s] == NSNotFound) {
[resultArray addObject:s];
}
}
NSString *resultString = nil;
if ([resultArray count] > 0) {
resultString = [resultArray componentsJoinedByString:@" "];
} else {
resultString = srcString;
}
return resultString;
}_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden