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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:03:21+00:00 2026-06-16T23:03:21+00:00

I have random data (names) in strings that I need to compare. Data (names)

  • 0

I have random data (names) in strings that I need to compare. Data (names) will not always be the same but it will be in this format.

For example, I have two NSString like this:

NSString *string1= @"Jordan Mike Liam Taylor Jill Gordon Phil Mark";

NSString *string2= @"Marcus Tony Taylor Anny Keenan Brittany Gordon Mike";

Based on these 2 strings, we can see that both strings contain Mike| Taylor | Gordon

So the count of same data between these two strings is 3. However I am not able to get it work via code.
The following below is what I have thus far. I feel that I am close but not quite there and would really appreciated some help from the community. Thank you in advance!

NSMutableArray *tempArray= [[NSMutableArray alloc] init];
[tempArray addObject:string1];
[tempArray addObject:string2];

NSCountedSet *bag = [[NSCountedSet alloc] initWithArray:tempArray];

NSString *mostOccurring;
NSUInteger highest = 0;
for (NSString *s in bag)
{
    if ([bag countForObject:s] > highest)
    {
        highest = [bag countForObject:s];
        mostOccurring = s;
    }
}
NSLog(@"Most frequent string: %d", highest);

EDIT CODE

NSUInteger highest = 1;
NSUInteger theCount=0;
for (NSString *s in bag)
{
    if ([bag countForObject:s] > highest)
    {
        highest = [bag countForObject:s];
        mostOccurring = s;

    }
if (highest ==2)
{
    theCount++;
}

}
NSLog(@"Most frequent string: %d", theCount);
  • 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-16T23:03:23+00:00Added an answer on June 16, 2026 at 11:03 pm

    I am late to answer this question, but have a look here :

    NSString *string1= @"Jordan Mike Liam Taylor Jill Gordon Phil Mark a";
    NSString *string2= @"Marcus Tony Taylor Anny Keenan Brittany Gordon Mike";
    NSMutableSet *set1=[NSMutableSet setWithArray:[string1 componentsSeparatedByString:@" "]];
    NSMutableSet *set2=[NSMutableSet setWithArray:[string2 componentsSeparatedByString:@" "]];
    [set1 intersectSet:set2];
    
    NSArray *intersect=[set1 allObjects];//intersect contains all the common elements
    
    NSLog(@"Common count is  %ld.",[intersect count]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have this basic random quote script, but I would like it to
I have the following structures defined (names are anonymised, but data types are correct):
I have a Populater class for populating a database with random data. I would
I have a rake task to seed an application with random data using the
I have data in format: Randomtext1 (random2,random4) Randomtext2 (ran dom) Randomtext3 Randomtext4 (random5,random7,random8) So
I got requirements- 1. Have random values in a List/Array and I need to
I have some random string, let's say : s = This string has some
In a folder I have random module files. eg. user.rb that contains module User,
I have to convert a long string of data into values so that I
This is C#/.NET 2.0. So I have string that contains the future contents of

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.