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


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]);

3

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