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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to