【发布时间】:2011-04-03 07:12:17
【问题描述】:
有没有办法将目标 c 中的字符串拆分为数组?我的意思是这样 - 输入字符串 Yes:0:42:value 到 (Yes,0,42,value) 的数组中?
【问题讨论】:
标签: iphone objective-c function split
有没有办法将目标 c 中的字符串拆分为数组?我的意思是这样 - 输入字符串 Yes:0:42:value 到 (Yes,0,42,value) 的数组中?
【问题讨论】:
标签: iphone objective-c function split
NSArray *arrayOfComponents = [yourString componentsSeparatedByString:@":"];
其中 yourString 包含 @"one:two:three"
并且arrayOfComponents 将包含@[@"one", @"two", @"three"]
你可以使用NSString *comp1 = arrayOfComponents[0];访问每个
(https://developer.apple.com/documentation/foundation/nsstring/1413214-componentsseparatedbystring)
【讨论】:
[NSArray componentsJoinedByString:]。
如果你想访问第一个单词:
[[string componentsSeparatedByString:@" "] objectAtIndex:0];
【讨论】:
使用这个: [[字符串组件SeparatedByString:@","][0];
【讨论】:
试试这个:
NSString *testString= @"It's a rainy day";
NSArray *array = [testString componentsSeparatedByString:@" "];
【讨论】:
【讨论】: