Search code examples
iosswiftxcodensstringnsrange

Fetch Substring from NSString


I have the following string :

Item 1#Item 2#Item 3#Item 4#Item 5#Item 6#Item 7#Item 8#Item 9#Item 10#Item 11#Item 12#Item 13#Item 14#Item 15#

I want to extract each Item name. How can it be done?


Solution

  • try this

    NSString *temp = @"Item 1#Item 2#Item 3#Item 4#Item 5#Item 6#Item 7#Item 8#Item 9#Item 10#Item 11#Item 12#Item 13#Item 14#Item 15#";
        NSArray *arr = [temp componentsSeparatedByString:@" "];
        NSLog(@"%@", arr);