How to get the first N words from a NSString in Objective-C?

后端 未结 4 1389
无人及你
无人及你 2020-12-08 06:14

What\'s the simplest way, given a string:

NSString *str = @\"Some really really long string is here and I just want the first 10 words, for example\";
         


        
4条回答
  •  时光说笑
    2020-12-08 06:48

    Here's my solution, derived from the answers given here, for my own problem of removing the first word from a string...

    NSMutableArray *words = [NSMutableArray arrayWithArray:[lowerString componentsSeparatedByString:@" "]];
    [words removeObjectAtIndex:0];
    return [words componentsJoinedByString:@" "];
    

提交回复
热议问题