• 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
Huge and weird problem with NSScanner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Huge and weird problem with NSScanner


  • Subject: Huge and weird problem with NSScanner
  • From: Gustavo Adolfo Pizano <email@hidden>
  • Date: Thu, 2 Apr 2009 13:05:06 +0200

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

  • Follow-Ups:
    • Re: Huge and weird problem with NSScanner
      • From: Jonathan Hess <email@hidden>
  • Prev by Date: Re: Seeking advice on best practice for managing visibility of many subviews
  • Next by Date: Re: Huge and weird problem with NSScanner
  • Previous by thread: Content of the page cleared
  • Next by thread: Re: Huge and weird problem with NSScanner
  • Index(es):
    • Date
    • Thread