MCKapur
MCKapur

Reputation: 9157

Remove substring before a specific char (NSString)

Basically I am getting a users city throughout Facebook Connect. The result is always in this format:

Sydney, Australia

But since there will be many users, the city and country can vary. Here is the format: First the city with a comma, then a space and the country.

I only want to however retrieve the country name. Is it possible for me to locate the comma in string, then remove everything behind it. Then I can replaceOccurancesOfString:" " to remove the space.

I have seen other questions on this but they are in different languages. I am asking for Objective-C

Thanks!

Upvotes: 2

Views: 2740

Answers (1)

danqing
danqing

Reputation: 3668

one easy way to do it is to use - (NSArray *)componentsSeparatedByString:(NSString *)separator to make an array out of it, and then pick the second object of the array.

Upvotes: 2

Related Questions