有没有办法将 objective-c 中的字符串拆分为数组?我的意思是这样 - 输入字符串 Yes:0:42:value 到 (Yes,0,42,value) 的数组中?
最佳答案
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 )
关于iphone - Objective-C 拆分()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3558888/