itZme
itZme

Reputation: 1439

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?

Upvotes: 2

Views: 1542

Answers (2)

Ishu
Ishu

Reputation: 12787

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;
}

Upvotes: 0

John Lemberger
John Lemberger

Reputation: 2699

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

Upvotes: 7

Related Questions