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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:23:53+00:00 2026-05-24T18:23:53+00:00

how to get the sorted NSArray from the NSArray that contains number string with

  • 0

how to get the sorted NSArray from the NSArray that contains number string with two decimal points. Can anyone help me in this regard. Thanks in advance.

  • 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-24T18:23:55+00:00Added an answer on May 24, 2026 at 6:23 pm

    This should do the trick for you:

    NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
    
    NSArray *sortedArray = [unsortedArray sortedArrayUsingComparator:^(id obj1, id obj2) {
      if ([obj1 isKindOfClass:[NSString class]] && [obj2 isKindOfClass:[NSString class]]) {
        NSArray *obj1Components = [(NSString *)obj1 componentsSeparatedByString:@"."];
        NSArray *obj2Components = [(NSString *)obj2 componentsSeparatedByString:@"."];
    
        int highestCount = obj1Components.count;
        if (obj2Components.count > highestCount) {
            highestCount = obj2Components.count;
        }
    
        for (int i = 0; i < highestCount; i++) {
    
            // If the component does not exist, just make it 0
            NSNumber *num1 = [NSNumber numberWithInt:0];
            if (i < obj1Components.count) {
                num1 = [nf numberFromString:[obj1Components objectAtIndex:i]];
            }
    
            NSNumber *num2 = [NSNumber numberWithInt:0];
            if (i < obj2Components.count) {
                num2 = [nf numberFromString:[obj2Components objectAtIndex:i]];
            }
    
            int int1 = [num1 intValue];
            int int2 = [num2 intValue];
    
            if (int1 > int2) {
                return NSOrderedDescending;
            } else if (int2 > int1) {
                return NSOrderedAscending;
            }
        }
    
        // If we reach here, they're the same.
        return NSOrderedSame;
    
      } else {
          // They're not strings, so just say they're the same
          return NSOrderedSame;
      }
    }];
    
    [nf release];
    

    It’ll take something like [“1.4.2”, “0.4.9”, “1”, “3.3.3.3.3”] and turn it into [“0.4.9”, “1”, “1.4.2”, “3.3.3.3.3”]

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

Sidebar

Related Questions

I've a dictionary, which i sorted by value with linq, how can i get
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I have a GUI problem that I would like to get sorted out, but
I'm looking at this program that reads input lines and then sorts them, from
I can get a sorted filename list with the following code: $log_files = scandir(LLP_LOG_DIR);
I've been trying to get this sorted all day, but really cant figure it
I have a real problem, I can't get sorted out? I have a form
I'm trying to get sorted localized data from a core data model. My code:
How can I get the disk usage information that is in human readable format
I'm trying to get fulltext searches to be sorted by relevance in a Doctrine_RawSql

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.