Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C Split()?

People also ask

How do you split a string in Objective C?

If you need to split on a set of several different delimiters, use -[NSString componentsSeparatedByCharactersInSet:] . If you need to break a string into its individual characters, loop over the length of the string and convert each character into a new string.

How do I create an NSArray in Objective C?

Creating NSArray Objects Using Array Literals In addition to the provided initializers, such as initWithObjects: , you can create an NSArray object using an array literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method.

What is NSString?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.


NSArray *arrayOfComponents = [yourString componentsSeparatedByString:@":"];

where yourString contains @"one:two:three"

and arrayOfComponents will contain @[@"one", @"two", @"three"]

and you can access each with NSString *comp1 = arrayOfComponents[0];

(https://developer.apple.com/documentation/foundation/nsstring/1413214-componentsseparatedbystring)


Try this:

    NSString *testString= @"It's a rainy day";
    NSArray *array = [testString componentsSeparatedByString:@" "];

Try componentsSeparatedByString:


Use this: [[string componentsSeparatedByString:@","][0];