• 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
catching whitespace with scanner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

catching whitespace with scanner


  • Subject: catching whitespace with scanner
  • From: Daniel Child <email@hidden>
  • Date: Thu, 07 May 2009 01:05:17 -0400

I'm trying to catch whitespace between words with a scanner. For some reason, the white space is not being recognized.
Am I missing something obvious or is there a bug here? Thanks.


{
	NSMutableArray *separateWords;
	NSScanner *scanner;
	NSCharacterSet *spaceCharSet;
	NSString *oneWord, *whiteSpace;
	unichar whiteSpaceChar;

spaceCharSet = [NSCharacterSet whitespaceCharacterSet];
separateWords = [NSMutableArray array];
whiteSpace = [NSString stringWithString: @""];
scanner = [NSScanner scannerWithString: words]; // words IS A PASSED IN STRING THAT CONTAINS SPACES AND TABS


while (![scanner isAtEnd]) {
[scanner scanUpToCharactersFromSet: spaceCharSet intoString: &oneWord];
[separateWords addObject: oneWord];
[scanner scanCharactersFromSet: spaceCharSet intoString: &whiteSpace]; // whiteSpace SHOULD RECEIVE SPACES/TABS HERE

if ([whiteSpace isEqualToString: @" "]) {
NSLog(@"We caught a space.\n"); // NEVER GETS CAUGHT EVEN THOUGH words DEFINITELY HAS SPACES
}
if (whiteSpace) {
whiteSpaceChar = [whiteSpace characterAtIndex: 0];

if ((whiteSpaceChar == 0x0020) || (whiteSpaceChar == 0x0009)) { // SPACE OR TAB
[separateWords addObject: whiteSpace];
whiteSpace = @""; // need to reset to blank or it will keep accumulating characters
}
}
}
....
}


_______________________________________________

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: catching whitespace with scanner
      • From: Graham Cox <email@hidden>
    • Re: catching whitespace with scanner
      • From: "Adam R. Maxwell" <email@hidden>
  • Prev by Date: Re: NSXMLParser frees itself on error?
  • Next by Date: Re: catching whitespace with scanner
  • Previous by thread: Re: Dynamic Layout
  • Next by thread: Re: catching whitespace with scanner
  • Index(es):
    • Date
    • Thread