title: NSScanner behavior
body: <p>I am very new to iOS development.  I am trying to parse a simple csv file that has about 10 lines separated by commas. I am using the code below but not able understand why <code>NSScanner</code>, when parsing the fields (fields in the code below) does not go to the next string after the comma. I have to execute the line</p>
  
  <pre><code>[fields scanCharactersFromSet:fieldCharSet intoString:nil];
  </code></pre>
  
  <p>to make it go past the delimiter. However, I don't have to do the same thing for lines - <code>NSScanner</code> automatically sets the position to the next line past the newline. In both cases I am using the same method - [lines scanUpToCharactersFromSet:intoString] Is there something I am not understanding?</p>
  
  <p>Here is the test file I am trying to parse:</p>
  
  <pre><code>Name,Location,Number,Units
  A,AA,4,mm
  B,BB,3.5,km
  C,CC,10.2,mi
  D,DD,2,mm
  E,EE,6,in
  F,FF,2.8,m
  G,GG,3.7,km
  H,HH,4.3,mm
  I,II,4,km
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>-(void)parseFile {
      NSCharacterSet *lineCharSet = [NSCharacterSet newlineCharacterSet];
      NSCharacterSet *fieldCharSet = [NSCharacterSet characterSetWithCharactersInString:self.separator];
      // import the file
  
      NSStringEncoding *encoding = nil;
      NSError *error = nil;
      NSString *data = [[NSString alloc] initWithContentsOfURL:self.absoluteURL usedEncoding:encoding error:&amp;error];
      NSString *line,*field;
  
  
      NSScanner *lines = [NSScanner scannerWithString:data]; 
      while (![lines isAtEnd]) {
  
          [lines scanUpToCharactersFromSet:lineCharSet intoString:&amp;line];//automatically sets to next line - why?
  
  
  
          NSLog(@"%@\n",line);
  
          NSScanner *fields = [NSScanner scannerWithString:line];
  
          while (![fields isAtEnd]) {
  
              [fields scanUpToCharactersFromSet:fieldCharSet intoString:&amp;field];
  
              [fields scanCharactersFromSet:fieldCharSet intoString:nil]; //have to do this otherwise will not go to next symbol
  
              NSLog(@"%@\n", field);
  
          }
      }
  }
  </code></pre>