开发者

How i break or make NSMutableSubstrings from NSMutableString in objective-C in iphone?

I m the beginner in iphone Thanks for sending me answer.... I want to break following NSMutable string into substring

200,8,"7 Infinite Loop, Cupertino, CA 95014, USA"

I wanting only Cupertino and CA from above Mutable String. can it is possible in iphone in objective-C The above data is the mutable data, which is came from httprequest object. I want to fetching the city and state name from above same开发者_如何学Python kind og mutable strings. please give me the solution it creating a lot of hedac for me.


If this is CSV data, check out

http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data


One method would be to split the string at commas and trim whitespace:

NSArray *substrings = [myString componentsSeparatedByString: @","];
NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet];
NSMutableArray *result = [NSMutableArray array];
for ( NSString *str in substrings )
    [result addObject: [str stringByTrimmingCharactersInSet: whitespace]];


Are all of the strings that you want to break apart in this format?

NSArray *myArray = [string componentsSeparatedByString:@","];
NSString * strippedNumbers = [[myArray objectAtIndex:4] stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
NSString *myString = [NSString stringWithFormat:@"%@ %@", [myArray objectAtIndex:3], strippedNumbers];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜