-6

Possible Duplicate:
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.

Community
  • 1
  • 1
kiran kumar
  • 1,349
  • 4
  • 21
  • 40

1 Answers1

1

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]);
Alex Terente
  • 12,006
  • 5
  • 51
  • 71