Getting the last word of an NSString

前端 未结 7 1059
滥情空心
滥情空心 2020-12-17 00:38

As the title suggests, I would like to get the last word out of an NSString. I thought using this code:

NSArray *listItems = [someNSStringHere componentsSepa         


        
相关标签:
7条回答
  • 2020-12-17 01:03

    That works great as it also recognizes symbols like @ and # which enumerateSubstringsInRange: doesn't do.

    NSCharacterSet *charSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSArray *components = [someString componentsSeparatedByCharactersInSet:charSet];
    NSString *lastWord = components.lastObject;
    
    0 讨论(0)
提交回复
热议问题