• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Huge and weird problem with NSScanner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Huge and weird problem with NSScanner


  • Subject: Re: Huge and weird problem with NSScanner
  • From: Gustavo Pizano <email@hidden>
  • Date: Thu, 2 Apr 2009 16:50:33 +0200

I think I have a solution, it seems that the encoding of the text file, which was an output from a Piece Of Crap computer AKA PC: windows, was different from the one Im using inside the application, so what I did was to open the file and save it with the proper encoding, then all its seems to be working.. so far...


Gustavo

On 2.4.2009, at 13:15, Jonathan Hess wrote:

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


References: 
 >Huge and weird problem with NSScanner (From: Gustavo Adolfo Pizano <email@hidden>)
 >Re: Huge and weird problem with NSScanner (From: Jonathan Hess <email@hidden>)

  • Prev by Date: core data, opening a previously saved xml file... bug/glitch/unexpected behavior
  • Next by Date: Re: disable row highlighting NSTableView
  • Previous by thread: Re: Huge and weird problem with NSScanner
  • Next by thread: bitmapImageRepForCachingDisplayInRect & CALayers ...
  • Index(es):
    • Date
    • Thread