Split a NSString into an NSArray

Discussion in 'Mac Programming' started by subo, Jan 11, 2010.

  1. subo macrumors newbie

    Joined:
    Jan 11, 2010
    #1
    I have an NSString*

    NSString *str = @"the---quick-------brown--fox----jumps";

    How can i create an NSArray from it like this, Thanks!

    Array {

    'the',
    '---',
    'quick',
    '-------',
    'brown',
    '--',
    'fox',
    '----',
    'jumps'

    }
     
  2. subo thread starter macrumors newbie

    Joined:
    Jan 11, 2010
    #3
    I tried this but dont know how to go futher:
    NSString *str = @"the---quick-------brown--fox----jumps";
    NSCharacterSet *lineSeparatingSet = [NSCharacterSet characterSetWithCharactersInString:mad:"-"];
    NSArray *lines = [str componentsSeparatedByCharactersInSet:lineSeparatingSet];

    NSLog(@"%@", lines);
     
  3. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000

Share This Page