Re: [Q] NSScanner -> \t\t how to fix??
Re: [Q] NSScanner -> \t\t how to fix??
- Subject: Re: [Q] NSScanner -> \t\t how to fix??
- From: Ali Ozer <email@hidden>
- Date: Sat, 7 Feb 2004 09:21:41 -0800
In addition to what Clark said, your loop needs to change a bit. You
are basically telling it to scan a string up to tab, but then not
skipping over the tab. So the second attempt to read a string fails (an
empty string returns FALSE; you are already on the tab), and the loop
exits.
Something like the following should work, assuming row contains a
single row worth of characters, with no terminating end-of-line. It
scans a string upto tab, and stops when no more tabs are left. An empty
string will give you one item.
do {
if (![ rowscan scanUpToString:@"\t" intoString:&field] ) field =
@"";
// do something
CFShow( field );
} while ([rowscan scanString:@"\t" intoString:NULL]);
Note that if this is the behavior you want, you can also do this with
-[NSString componentsSeparatedByString:].
Ali
Begin forwarded message:
From: Clark Cox <email@hidden>
Date: February 7, 2004 8:16:59 PST
To: Rogier Bosch <email@hidden>
Cc: email@hidden, email@hidden
Subject: Re: [Q] NSScanner -> \t\t how to fix??
On 2004/02/07, at 10:03, Rogier Bosch wrote:
OK, that makes sence, but:
i have now, something like:
NString *row, *field;
// the row is filled with an other loop (ascii file row)
NSScanner *rowscan = [[NSScanner alloc]
setCharactersToBeSkipped:nil];
[rowscan initWithString:row]; // setCharactersToBeSkipped:nil];
Try this instead:
NSScanner *rowscan = [[NSScanner alloc] initWithString:row];
[rowscan setCharactersToBeSkipped: [NSCharacterSet
characterSetWithCharactersInString: @""]];
while ( [ rowscan scanUpToString:@"\t" intoString:&field] ) {
// do something
CFShow( field );
}
When i use the code above it doesnt return any field! :(
So whats wrong?
thx.
Roger
On 6-feb-04, at 19:58, Jonathan E. Jackel wrote:
This is one of those hidden things in the docs. You can set which
characters are skipped by the scanner. The default set of characters
to
skip is the whitespace and newline character set. Sneaky.
To make sure characters are not skipped, use [scanner
setCharactersToBeSkipped:nil], or construct a character set that has
the
characters you want skipped and doesn't have the ones you want
scanned.
Jonathan
-----Original Message-----
From: email@hidden
[mailto:email@hidden]On Behalf Of Rogier Bosch
Sent: Friday, February 06, 2004 8:26 AM
To: email@hidden
Subject: [Q] NSScanner -> \t\t how to fix??
Hay,
When i use the NSScanner on a flat file, it skips double \t\t (tab
char).
Is there anyway to NOT skip this char?
I ask this because in the 1st line of the flat file i have the
columnnames. The next rows contains the data lines (just a CSV
file).
So when parsing the file i do have the column-headers but i can't
keep
it in sync with the data fields (since some fields are empty, e.a
\t\t).
Thanks,
Rogier
[demime 0.98b removed an attachment of type
application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
[demime 0.98b removed an attachment of type
application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
[demime 0.98b removed an attachment of type
application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.