Question

Objective-C: Best way to extract substring from NSString?

I have a space-separated string like @"abc xyz http://www.example.com aaa bbb ccc".

How can I extract the substring @"http://www.example.com" from it?

 45  70055  45
1 Jan 1970

Solution

 59

I know this is a very late reply, but you can get the substring "http://www.abc.com" with the following code:

[@"abc xyz http://www.abc.com aaa bbb ccc" substringWithRange:NSMakeRange(8, 18)]

Of course, you can still use an NSString for that.

2011-08-11

Solution

 30

Try this:

       [yourString substringToIndex:<#(NSUInteger)#>];
//or
      [yourString substringFromIndex:<#(NSUInteger)#>];
//or        
      [yourString substringWithRange:<#(NSRange)#>];
2013-01-24