Using NSScanner to scan up to and include the separator character?
<p>I have a string that's basically dates into a string with extra whitespace in some areas for formatting when showing the string.  So the string can look something like</p>

<pre><code>6:00 PM 
6:00 PM  4:00 AM
6:00 PM  4:00 AM 12:00 PM
6:00 pm  4:00 AM 12:00 PM  1:00 AM
</code></pre>

<p>I figured I could use NSScanner to parse the string by the @"M" since sometimes there are two spaces between times, sometimes a single space, etc.  So what I did was:</p>

<pre><code>    NSScanner *theScanner = [NSScanner scannerWithString:theString];
    NSString *separatorString = @"M";
    NSString *container;
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:_lastIndexPath.row];

    while ([theScanner isAtEnd] == NO) {
        [theScanner scanUpToString:separatorString intoString:&amp;container];
        [array addObject:container];

        [theScanner setScanLocation:[theScanner scanLocation] + 1];
    }
</code></pre>

<p>The problem is I do not get the M in my container object since it scans up to but it doesn't include the separator string.  Should I just manually create a new NSString before adding it like</p>

<pre><code>[array addObject:[NSString stringWithFormat:%@M", container]];
</code></pre>

<p>Or is there a better way to use NSScanner in this scenario?  I really haven't used NSScanner before.  Thanks.</p>
