Amogh Talpallikar
Amogh Talpallikar

Reputation: 12184

Compare two Strings in Objective C without considering case,punctuation marks and whitespace characters

I am sorting An Array of Strings using a comparator block. The comparison logic of two strings should leave aside case,punctuation marks like apostrophes ,commas and full stops and also white space characters.

UPDATE:

Strip Non-Alphanumeric Characters from an NSString

Just saw this SO post, used this to do a case-Insensitive comparison of strings after removing non alphanumeric characters.

Upvotes: 1

Views: 539

Answers (1)

Christian Stieber
Christian Stieber

Reputation: 12496

You'll have to make a temporary string that has the characters that you don't like to participate in the comparison removed.

If you have a lot of strings you might want to cache these temporary strings (like in a dictionary with the real string as key and the temp string as data), or implement your own comparision function so you don't have to repeatedly create and discard those temporary strings.

Upvotes: 1

Related Questions