简体   繁体   中英

How to get NSString between two words?

I have NSString in the following format

NSString *string1 = @"webservices/employee/1"; and another string with
NSString *string2 = @"webservices/manaager/1";

I want to get the string in between "werbservice/" and "/1" using a common method.

Is there any way to do this?

[[string componentsSeparatedByString:@"/"] objectAtIndex:1]

use this method for deviding the string - (NSArray *)componentsSeparatedByString:(NSString *)separator

use like this

-(NSString *)returnComponent:(NSString *)str
{
   NSString *returnString=[[str componentsSeparatedByString:@"/"] objectAtIndex:1];

return returnString;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM