Really? OK. On 21 Sep 2014, at 00:05, SevenBits <sevenbitst...@gmail.com> wrote:
> On Sep 20, 2014, at 1:01 PM, 2551 <2551p...@gmail.com> wrote: > >> I've searched high and low (or roundabouts in circles) for a built in method >> that will return the difference between two strings as a string. >> >> I hacked up this solution below, but it feels cludgy and isn't very robust >> (punctuation will mess it up a little); worse, I can't help feeling I must >> be reinventing the wheel. Finding the string that is the difference between >> two other strings must be a basic need. How do you guys do this? > > Define what you mean the “difference between two strings”. For example: NSString *mary = @"mary had a little lamb, a little lamb she had"; NSString *scary = @"mary had a little lamb, a little naughty fella of a lamb she had for sure"; NSString *isDifferent = [self getDifference:mary and: scary]; NSLog(@"%@", isDifferent); The method I posted below produces the difference that I want ("naughty fella of a for sure"). But I want to know if there's a more orthodox and robust solution. > >> >> >> >> -(NSString *)getDifference: (NSString *)aString and:(NSString >> *)anotherString { >> int i = aString.length; >> int j = anotherString.length; >> NSString *result, *longest, *shortest; >> >> if (i == j) { >> result = @""; >> return result; >> } >> >> if (i > j) { >> longest = aString; >> shortest = anotherString; >> } else { >> longest = anotherString; >> shortest = aString; >> } >> >> NSArray *fa = [longest componentsSeparatedByString: @" " ]; >> NSArray *sa = [shortest componentsSeparatedByString: @" "]; >> NSMutableArray *remainder = [NSMutableArray arrayWithArray:fa]; >> [remainder removeObjectsInArray:sa]; >> result = [remainder componentsJoinedByString:@" "]; >> return result; >> >> } >> >> _______________________________________________ >> >> 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: >> https://lists.apple.com/mailman/options/cocoa-dev/sevenbitstech%40gmail.com >> >> This email sent to sevenbitst...@gmail.com >
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com