有没有办法把目标 c 中的字符串分解成数组呢?我的意思是像这样-输入字符串 Yes: 0:42: value 到一个数组中(Yes,0,42,value) ?
NSArray *arrayOfComponents = [yourString componentsSeparatedByString:@":"];
你的字符串在哪里包含 @"one:two:three"
@"one:two:three"
组件数组将包含 @[@"one", @"two", @"three"]
@[@"one", @"two", @"three"]
你可以通过 NSString *comp1 = arrayOfComponents[0];访问每一个
NSString *comp1 = arrayOfComponents[0];
(https://developer.apple.com/documentation/foundation/nsstring/1413214-componentsseparatedbystring)
试试 ComponentsSeparatedByString:
试试这个:
NSString *testString= @"It's a rainy day"; NSArray *array = [testString componentsSeparatedByString:@" "];
如果你想访问第一个单词:
[[string componentsSeparatedByString:@" "] objectAtIndex:0];
Use this: [字符串组件:@“ ,”][0] ;