Hello I have an NSString * ParamString - it contains a record of the form firstparam / secondparam. I need to pull out the firstparam and secondparam variables into other variables. That is:

NSString FirstParamString = firstparam; // text to a slash NSString SecondParamString = secondparam; // text after slash

Tell me please.

2 answers 2

For this task, the regulars are not required, enough method

- (NSArray *)componentsSeparatedByString:(NSString *)separator; 

Example of use for your task:

 NSString *paramsString = @"first/second"; NSArray *params = [paramsString componentsSeparatedByString:@"/"]; NSString *firstParam = [params objectAtIndex:0]; NSString *secondParam = [params objectAtIndex:1]; 

    Regular expression here would be superfluous, I think.

    In Objective C, there are componentsSeparatedByString:

     NSString *ParamString= @"firstparam/secondparam"; NSArray *array = [ParamString componentsSeparatedByString:@"/"]; 

    Only the result will be returned as an array. But then you can assign each variable one of the elements of the array. Or maybe you can assign it right away. You should be better. I just have never seen Objective C.

    Here you can read about all the available methods for the NSString class.