Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:48:45+00:00 2026-05-17T15:48:45+00:00

OK, first and foremost, I am using GNUStep as a way to learn Objective-C,

  • 0

OK, first and foremost, I am using GNUStep as a way to learn Objective-C, so there may be some differences between the GNU and the Apple implementation. That being said, it shouldn’t affect my question.

Anyways, to understand my conundrum, please parse the following code into your visual receptacles:

#import <Cocoa/Cocoa.h>
int main()
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  NSEnumerator * LineEnumerator = [[NSArray arrayWithObjects: @"Jim     1", @"Steve   3", nil] objectEnumerator];
  NSString * s;
  while((s = [LineEnumerator nextObject]))
  {
    NSArray * parts = [s componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSLog(@"%@", parts);
  }
  [pool drain];
  return NO;
}

And the following output:

2010-10-07 10:03:50.809 a.out[24512] (Jim, "", "", "", "", 1)
2010-10-07 10:03:50.812 a.out[24512] (Steve, "", "", 3)

My expected output would be:

2010-10-07 10:03:50.809 a.out[24512] (Jim, 1)
2010-10-07 10:03:50.812 a.out[24512] (Steve, 3)

But the componentsSeparatedByCharactersInSet seems to be the only method that comes close to what I am looking for (by the way, I want to be prepared for any mixture of spaces, tabs, or other whitespace characters). Is there an easy way to do this with the standard libraries without writing a new method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:48:46+00:00Added an answer on May 17, 2026 at 3:48 pm

    I think you’ll have to use NSScanner:

    while((s = [LineEnumerator nextObject]))
    {
        NSMutableArray *parts = [[NSMutableArray alloc] initWithCapacity:1];
    
        NSScanner *scanner = [NSScanner scannerWithString:s];
        NSString *token;
        while ([scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet] intoString:&token]) {
            [parts addObject:token];
        }
    
        NSLog(@"%@", parts);
        [parts release];
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, some context: I'm a Python developer who has written a medium-sized application using
Please no jQuery code, as I want to learn javascript first and foremost. I
First and foremost, are there many android developers here? Is this a good place
First and foremost, thank you all for reading this and helping, I'm very grateful.
First and foremost, I've been learning JS for about 2-3 hours. I've lost track.
first of all some details: I configured security as below in web.xml view plaincopy
First and foremost thank you for checking out my problem, and for any help
I am first and foremost a perl coder, but like many, also code in
First and foremost, I do not know RegEx but am trying to piece something
First and foremost. I'm totally new to programming in Excel. I'm trying to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.