How to separate string by space using Objective-C?

前端 未结 5 2138
清歌不尽
清歌不尽 2021-01-30 16:16

Assume that I have a String like this:

hello world       this may     have lots   of sp:ace or little      space

I would like to seperate this

5条回答
  •  情歌与酒
    2021-01-30 17:02

    NSString *aString = @"hello world       this may     have lots   of sp:ace or little      space";
    NSArray *array = [aString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    array = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
    

提交回复
热议问题