Sai
Sai

Reputation: 59

Splitting string into substring in iOS

I have a small doubt on splitting a string into substring. I want to display State and Country name in one label. i have a string in a service coming from json file "FullAddress": "New Windsor,New York,USA". i want only New York,USA to display in a label.

Upvotes: 0

Views: 92

Answers (2)

Ajharudeen khan
Ajharudeen khan

Reputation: 246

Please Use this code it will be help you out

NSString *fullAddress=@"New Windsor,New York,USA";

    NSRange range=[fullAddress rangeOfString:@","];
    if (range.location!=NSNotFound) {
        NSString *string=[fullAddress substringFromIndex:range.location+range.length];//this is address you want
        NSLog(@"%@",string);
    }

Upvotes: 0

rohit Sidpara
rohit Sidpara

Reputation: 547

Use this and get your desire String from Array element 1 and 2

NSArray *strings = [FullAddress componentsSeparatedByString:@","];

Upvotes: 4

Related Questions