Re: Huge and weird problem with NSScanner
Re: Huge and weird problem with NSScanner
- Subject: Re: Huge and weird problem with NSScanner
- From: Jonathan Hess <email@hidden>
- Date: Thu, 2 Apr 2009 04:15:41 -0700
Hey Gustavo -
This is probably auxiliary to your problem, but are you running 32-bit
or 64-bit? The reason I ask is that the %i format specifier is for an
'int', but NSUInteger is a 'unsigned long' when running 64 bit.
You should probably change that NSLog line to
NSLog(@"initial %lu", (unsigned long)sil);
Which will work correctly on 64 and 32 bit Mac OS X.
Jon Hess
On Apr 2, 2009, at 4:05 AM, Gustavo Adolfo Pizano wrote:
Hello, Im reading a txt file, big one, and the only way (I see) to
read specific areas of the file for my final goal, is using the
NSScanner. now, I set up the Scanner with the string I get from the
file like this:
inputString = [ NSString stringWithCString:[ inputData bytes ]
encoding:NSISOLatin1StringEncoding];
NSScanner * theScanner = [NSScanner scannerWithString: inputString];
now i need to look for the code that its bellow this "header"
--------[ Nainštalované programy
]--------------------------------------------------------------------------------------
So I do the following, having in mind that the .txt comes from a pc
machine, so I change the encoding and so on.
NSString * cadInitToSearch = @"--------[ Nainštalované
programy
]--------------------------------------------------------------------------------------";
NSData * temp = [cadInitToSearch
dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
NSString * stirngEncoded;
stirngEncoded = [NSString stringWithCString:[temp bytes]
encoding:NSISOLatin1StringEncoding];
[theScanner scanUpToString:stirngEncoded intoString:NULL];
[theScanner scanString:stirngEncoded intoString:NULL];
Im getting the scan location after I read that string.
NSUInteger sil = [theScanner scanLocation];
NSLog(@"initial %i",sil);
now the funny thing comes, when I build and run, it didn't work, the
sil variable was showing me the value of the last location of the
inputString, then, without doing anything else, I just build again
and run and this time the sil variable was showing me real value for
where that specified string is, and if I click the button that calls
this method couple of times more it still shows me the real location
of that string but suddenly it shows me again the last location of the
inputString.
If I compile once again, then it shows the last location of the
inputString, and if I build (compile) again, it shows me the actual
location of the specified string.
Any suggestions??
Thanks for the help
Gustavo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden