Objective-C Split()?

Chr*_*art 108 iphone split function objective-c

有没有办法将目标c中的字符串拆分成数组?我的意思是这样的 - 输入字符串是:0:42:值为数组(是,0,42,值)?

mip*_*adi 196

-[NSString componentsSeparatedByString:]

  • 注意反函数是`[NSArray componentsJoinedByString:]`. (28认同)
  • @AuRis首先尝试修剪字符串中的空格:[string stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]]; (2认同)

Pra*_*abh 95

试试这个:

    NSString *testString= @"It's a rainy day";
    NSArray *array = [testString componentsSeparatedByString:@" "];
Run Code Online (Sandbox Code Playgroud)