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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:49:22+00:00 2026-06-06T21:49:22+00:00

I am trying to make this code work, the idea is to compare two

  • 0

I am trying to make this code work, the idea is to compare two arrays of strings, first is names and second is words, so I try to find the word from first array, then compare it to all words in second array, and if I get positive result, I print the word out. But it doesn’t work as intended, it just prints all the array of names. What’s wrong with this code? Maybe there is a more effective way to do this?

for (NSString *n in names) {

        for (NSString *m in words) {
            if ([n caseInsensitiveCompare:m] == NSOrderedSame) {
                NSLog(@"%@", n);
            }

        }          
    }

I tried another way and it just keeps printing names one after another. Tried swapping words for names for same result. Something is wrong with comparing to each other.

  for (NSString *n in names) {
            NSString *newN = [n lowercaseString]; 

            for (NSString *m in words) {
                NSString *newM = [m lowercaseString];

                if ([newN isEqualToString: newM]) {
                    NSLog(@"%@ is equal to %@", newN, newM );
                }

            }          
        }

This thing provides same results! Duh.

NSArray *names = [nameString componentsSeparatedByString:@"\n"];
NSArray *words = [itemsString componentsSeparatedByString:@"\n"];

int i = 0;
int j = 0;
while (i != [names count] ) {

    while (j != [words count]) {
        if ([[names objectAtIndex:i] caseInsensitiveCompare:[words objectAtIndex:j]] == NSOrderedSame)
        {
            NSLog(@"Voila! Name is : %@", [names objectAtIndex:i]);
        }
        j++;
    }
    j = 0;
    i++;

What is wrong? I can’t figure out, I tried. If you pick words one by one from either array, you get correct names and words. Words array does not have most names in it as the output I get. I get just names in order, Aaron, Aasomething, etc, they are not in words array.

  • 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-06T21:49:23+00:00Added an answer on June 6, 2026 at 9:49 pm

    Actually I have found an answer. The words file contains all the names from the names file. So you just get all the names. All three code variants work as intended.

    Well, at least I learned something new today.

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

Sidebar

Related Questions

I'm trying to figure out how to make this code work. Basically i have
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to make a multithreaded server/client app with java ! this code is
I am trying to make a simple alarm. in this code portion a take
I'm trying to make a python binding for the this library: http://code.google.com/p/hosterslib/ . I'm
Currently I'm trying to make a flowchart, this is the code I've got so
I get this error when trying to make the executable, the code compiles correctly
I am trying to make this sample program work (defn foo ([x] (foo x
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I'm trying to make this: 174,myfilename.jpg Into this on the php post process page:

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.