Convert comma separated list into array?

Discussion in 'Mac Programming' started by Locker, Nov 29, 2009.

  1. Locker macrumors 6502

    Joined:
    Aug 22, 2007
    Location:
    Staffordshire, UK
    #1
    I have a webpage which will generate a comma separated list of numbers. I want to get these numbers into an NSMutableArray. How would I go about doing so?
     
  2. Aquis macrumors member

    Joined:
    Aug 7, 2007
    Location:
    Staffordshire, UK
    #2
    Assuming you've read the list into a string:
    Code:
    NSArray * list = [theString componentsSeperatedByString:@","];
    To make a mutable version of that array:
    Code:
    NSMutableArray * mutableList = [NSMutableArray arrayWithArray:list];
    Edit: That will make a list of strings though; if you want NSNumbers to be in the array, you'll probably have to loop through and change them.
     
  3. Locker thread starter macrumors 6502

    Joined:
    Aug 22, 2007
    Location:
    Staffordshire, UK

Share This Page