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 8709065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:16:36+00:00 2026-06-13T04:16:36+00:00

I want to compare each character in an nsstring one by one to different

  • 0

I want to compare each character in an nsstring one by one to different nscharactersets and perform different operations according to the characterset it matches.

I’m able to assign each character to a substring for comparison using a for loop.

- (void) compareCharactersOfWord: (NSString *) word {

    for (int i = 0; i<[word length]; i++) {

        NSString *substring = [word substringWithRange:NSMakeRange(i,1)];


        //need to compare the substring to characterset here

    }
}

I also have my two charactersets

 setOne = [[NSCharacterSet characterSetWithCharactersInString:@"EAIONRTLSU"]invertedSet];

 setTwo = [[NSCharacterSet characterSetWithCharactersInString:@"DG"] invertedSet];

I’m a bit lost on the comparison part. I tried different methods like “rangeOfCharacterFromSet” but I kept getting erros. in pseudocode I would need something like

if (setOne containsCharacterFrom substring) {

//do stuff here

} else if (setTwo containsCharacterFrom substring) {

//do other stuff here

}
  • 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-06-13T04:16:37+00:00Added an answer on June 13, 2026 at 4:16 am

    To see if your ‘substring’ variable in one of your sets you would do:

    if ([substring rangeOfCharacterFromSet:setOne].location != NSNotFound) {
        // substring is in setOne
    } else if ([substring rangeOfCharacterFromSet:setTwo].location != NSNotFound) {
        // substring is in setTwo
    }
    

    Another option is to work with characters.

    for (int i = 0; i<[word length]; i++) {
        unichar ch = [word characterAtIndex:i];
    
        if ([setOne characterIsMember:ch]) {
            // in setOne
        } else if ([setTwo characterIsMember:ch]) {
            // in setTwo
        }
    }
    

    There one big limitation to the second option. It doesn’t work with Unicode characters higher than 0xFFFF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare each pixel in jpg's File A and File B on
I want to compare count of operations of the sorting algorithms Merge Sort and
I want to compare the alpha channel from one image to ~1000 other images.
We want to compare general performance (CPU, I/O, network, ...) of different JVMs for
I want to compare two CSV files to see if they are different. I
I have two vectors containing strings. I want to compare each string of vector1
I have a list of dicts and I want to compare each dict in
I have two recordsets rs1 and rs2 in vb6. i want to compare each
while writing an algorithm dealing with excel data if we want to compare each
I have an array of hashes, and I want to compare each only to

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.