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?
NSString *needle = [haystack componentsSeparatedByString:@":"][1]; This one creates three temporary strings and an array while splitting. All snippets assume that what's searched for is actually contained in the string. Ky.
Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
Working with NSString. Instances of the class NSString are immutable – their contents cannot be changed. Once a string has been initialized using NSString, the only way to append text to the string is to create a new NSString object. While doing so, you can append string constants, NSString objects, and other values.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With