开发者

Objective-C Split()?

开发者 https://www.devze.com 2023-01-13 02:19 出处:网络
Is there any way to split strings 开发者_Python百科in objective c into arrays? I mean like this - input string Yes:0:42:value into an array of (Yes,0,42,value)?NSArray *arrayOfComponents = [yourString

Is there any way to split strings 开发者_Python百科in objective c into arrays? I mean like this - input string Yes:0:42:value into an array of (Yes,0,42,value)?


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


if you want access first word:

[[string componentsSeparatedByString:@" "] objectAtIndex:0];
0

精彩评论

暂无评论...
验证码 换一张
取 消