Storing an NSString in an array

Discussion in 'iOS Programming' started by ac1, Feb 18, 2011.

  1. ac1 macrumors newbie

    Joined:
    Jan 17, 2011
    #1
    I'm having a bit of trouble with this. My app takes a csv file from the web, parses it and then "should" be displaying the results into a UITableView.

    I used a similar idea to get another app to take parsed csv data and use it to display map annotations, but this time I am working with strings (rather than floatvalues)

    Is there any way of taking parsed csv data and putting it as a strings into an nsarray?
     
  2. multinode macrumors regular

    Joined:
    Feb 4, 2011
    #2
    I'm not familiar with CSV files, but if you parsed it to get NSStrings, then alloc and init a NSMutableArray and use the following method for each NSString you want to add:

    - (void)addObject: (id)anObject
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    NSString's componentsSeparatedByString: instance method could come in awfully handy.
     
  4. ac1 thread starter macrumors newbie

    Joined:
    Jan 17, 2011
    #4
    Code:
    	NSScanner *scanner = [NSScanner scannerWithString:fileString];
    	csvcomments = [[NSMutableArray array] retain];
    	Comments *event;
    	NSString *line;
    	NSArray *values;
    	while ([scanner isAtEnd] == NO) {
    		[scanner scanUpToString:@"\n" intoString:&line];
    		//skip the first line
    		if(count > 0) {
    			values = [line componentsSeparatedByString:@","];
    			event = [[[Comments alloc] init] autorelease];
    			event.weekday = [[values objectAtIndex:0] floatValue];
    			event.time = [[values objectAtIndex:1] floatValue];
    			event.comment = [[values objectAtIndex:2] floatValue];
    			[csvcomments addObject:event];
    
    
    Problem is I don't want these things as floatvalues, but as strings instead?
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    componentsSeparatedByString: returns an NSArray of NSStrings.
     

Share This Page