2016-06-21 159 views
0

我對將字符串拆分爲子字符串有點懷疑。 我想在一個標籤中顯示州和國名。我有一個來自json文件「FullAddress」的服務中的字符串:「New Windsor,New York,USA」。我只希望美國紐約在標籤上展示。在iOS中將字符串拆分爲子字符串

+3

那麼究竟是什麼問題?你還沒有讀過'NSString'類的引用,你希望我們把它背誦給你? – Avi

+1

你能分享json的反應嗎? – Pushkraj

回答

4

使用此,並得到你的願望StringArray元素1和2

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

而不是1和2它可能是'[數組數] - 2'和'[數組數] -1'。 – Droppy

0

請使用此代碼,它將幫助你

NSString *[email protected]"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); 
    }