• 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
NSScanner stoopid question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSScanner stoopid question


  • Subject: NSScanner stoopid question
  • From: Koen van der Drift <email@hidden>
  • Date: Fri, 4 Apr 2003 21:34:36 -0500

Hi,

I am scanning a string for a specific character. However, if the next
character belongs to another NSCharacterSet, I should not continue with the
algorithm.

Here's a snippet:


NSScanner *scanner = [NSScanner scannerWithString: myString];
int len = [myString length];
int current;

while (![scanner isAtEnd])
{
[scanner scanUpToCharactersFromSet: firstSet intoString:nil];

current = [scanner scanLocation];

if ( len != current + 1 )
{
if ( ![restrictionSet characterIsMember:
[myString characterAtIndex: current + 1 ]])
{
...
}
}
}


So I first test if the current position is past the length of the string
before I test the character at current + 1.

However, if current happens to be len, then (len != current + 1) is false
and the following line give and "[NSCFString characterAtIndex:]: Range or
index out of bounds" error.

There probably must a very simple solution for this, but I fail to see it :(

I have been sitting too long in the sun and staring too long at my screen,
and can't figure out how to solve this, so any help is appreciated.


thanks,

- Koen.
_______________________________________________
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.

  • Prev by Date: Re: Cocoa in CodeWarrior
  • Next by Date: Re: Newbie Question: Best view for list of strings? (Addendum: weird horizontal scrollbar/resize issues)
  • Previous by thread: Re: NSCalendar dateByAddingYears
  • Next by thread: Re: NSScanner stoopid question
  • Index(es):
    • Date
    • Thread