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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:21:22+00:00 2026-06-10T11:21:22+00:00

I am googling NSSting manipulation methods from last few hours. and found many on

  • 0

I am googling NSSting manipulation methods from last few hours. and found many on stack overflow like this here

I have a String “1800 Ellis St, San Francisco, CA 94102, USA”. String may have any number of “,” . I have to take the third last(San Franncisco) and last(USA) substring after “,”.

and output should be “San Franncisco USA“.

I have logic how to do this in my mind that but I am struggling to implement it.

I try this code for getting the position of last three “,” in string. but it’s not work for me

 NSInteger commaArr[3];

        int index=0;   
        int commaCount=0;

        for(unsigned int  i =  [strGetCityName length]; i > 0; i--)
        {
            if([strGetCityName characterAtIndex:i] == ',')
            {

                commaArr[index]=i;
                index++;
                ++commaCount;
                if(commaCount == 3)
                {
                    break;
                }
            }
        }

Thanks

  • 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-10T11:21:23+00:00Added an answer on June 10, 2026 at 11:21 am

    You can do it like this:

    NSString *s = @"1800 Ellis St, San Francisco, CA 94102, USA";
    NSArray *parts = [s componentsSeparatedByString:@","];
    NSUInteger len = [parts count];
    NSString *res;
    if (len >= 3) {
        res = [NSString stringWithFormat:@"%@%@", [parts objectAtIndex:len-3], [parts objectAtIndex:len-1]];
    } else {
        res = @"ERROR: Not enough parts!";
    }
    

    The componentsSeparatedByString: will split the string at ,, and stringWithFormat: will put the parts back together.

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

Sidebar

Related Questions

Googling it a bit I found this to be an interesting question. Would like
After googling for many hours for a solution for the above Sharepoint exception, I
Interesting one this. I did do a bit Googling on the it but here
After googling, I have only found only this sad forum question . Is it
Googling I've found this article: http://java.dzone.com/tips/generating-client-java-code It talk about how to generate a JAVA
After googling I haven't found the anwser to this question so I am going
Been googling for this and haven't found anything ... Does anybody know if there
From googling around it looks like Xcode (3.1 in my case) should be at
Googling and searching stack overflow did not return any results that I could recognize,
After googling, I found many solutions that don't seem to work or require permission

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.