开发者

How to store data from string into array with delimiter [duplicate]

开发者 https://www.devze.com 2023-03-10 02:19 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: 开发者_C百科 separate the ids and store in two different array
This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

开发者_C百科 separate the ids and store in two different array

String response=@" hr 123,124,125,126,127,128 hr st 234,235,236,237 st";

from hr to hr i need to store in one array.

from st to st i need to store in another array.

My service provider is playing with response.....

Please help me out.


There you go:

    NSMutableString *response = [NSMutableString stringWithString: @" hr 123,124,125,126,127,128 hr st 234,235,236,237 st"];

    [response replaceOccurrencesOfString:@" " 
                              withString:@"" 
                                 options:NSCaseInsensitiveSearch
                                   range:NSMakeRange(0, [response length])];




    NSRange firstAppearanceOfHr = [response rangeOfString:@"hr"];

    [response replaceCharactersInRange:firstAppearanceOfHr withString:@""];



    NSRange secondAppearanceOfHr = [response rangeOfString:@"hr"];

    NSString *hrString = [response substringWithRange:NSMakeRange(0, secondAppearanceOfHr.location)];

    NSArray *hrArray = [hrString componentsSeparatedByString:@","];

    NSLog(@"HrArray:%@",[hrArray description]);

    NSRange firstAppearaceOfSt = [response rangeOfString:@"st"];

    NSInteger startSt = firstAppearaceOfSt.location+firstAppearaceOfSt.length;
    NSString *stString  = [response substringWithRange:NSMakeRange(startSt, [response length] - startSt - 2)];

    NSArray *stArray = [stString componentsSeparatedByString:@","];

    NSLog(@"StArray:%@",[stArray description]);
0

精彩评论

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

关注公众号