cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: leave space from a nsstring and manage commas

I have this nsstring

Manhattan, New York, Stati Uniti

I want leave all space and I can use replacestring with @"", it's ok for me; my very problem is that I want put all element separate by commas in an array, is it possible?

for example the array'll be array = [Manhattan] [New York] [Stati Uniti]

thanks

Upvotes: 1

Views: 61

Answers (2)

mopsled
mopsled

Reputation: 8505

Use NSString's componentsSeparatedByString:

NSString *list = @"Manhattan, New York, Stati Uniti";
NSArray *cities = [list componentsSeparatedByString:@", "];

cities now holds: { @"Manhattan", @"New York", @"Stati Uniti" }

Upvotes: 4

pdesantis
pdesantis

Reputation: 879

Try something like this

NSArray *newArray = [stateString componentsSeparatedByString:@", "];

Upvotes: 3

Related Questions