2013-01-19 23 views
0

Web服務,我訪問返回此值:iPhone SDK:追加的NSString和計數數據

A1;A2;A3;A4;A5;B2;B10;B11;B12; 

我想返回由;分開的所有數據的總數。我怎樣才能做到這一點?我正在考慮在字符串內部做一個循環,在;之前得到值,但是對如何正確運行循環感到困惑。誰能幫我?提前致謝。 :)

回答

2

有很多字符串函數,你可以使用其中的一個,那就是componentsSeparatedByString

考慮到上面提到的返回值是一個NSString。

 
NSString *strResponse = @"A1;A2;A3;A4;A5;B2;B10;B11;B12;"; 
NSArray *arCount = [strResponse componentsSeparatedByString:@";"]; 
NSLog(@"Total objects in response is: %d", [arCount count]);