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

  • Home
  • SEARCH
  • 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 7067651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:41+00:00 2026-05-28T05:13:41+00:00

Hey I am looking for a way to extract a string from another string.

  • 0

Hey I am looking for a way to extract a string from another string. It could be any length and be in any part of the string so the usual methods don’t work.

For example
http://bla.com/bla?id=%1234%&something=%888%

What I want to extract is from id=% to the next %.

Any idea’s?

  • 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-28T05:13:42+00:00Added an answer on May 28, 2026 at 5:13 am

    Use the rangeOfString method:

    NSRange range = [string rangeOfString:@"id=%"];
    if (range.location != NSNotFound)
    {
       //range.location is start of substring
       //range.length is length of substring
    }
    

    You can then chop up the string using the substringWithRange:, substringFromIndex: and substringToIndex: methods to get the bits you want. Here’s a solution to your specific problem:

    NSString *param = nil;
    NSRange start = [string rangeOfString:@"id=%"];
    if (start.location != NSNotFound)
    {
        param = [string substringFromIndex:start.location + start.length];
        NSRange end = [param rangeOfString:@"%"];
        if (end.location != NSNotFound)
        {
            param = [param substringToIndex:end.location];
        }
    }
    
    //param now contains your value (or nil if not found)
    

    Alternatively, here’s a general solution for extracting query parameters from a URL, which may be more useful if you need to do this several times:

    - (NSDictionary *)URLQueryParameters:(NSURL *)URL
    {
        NSString *queryString = [URL query];
        NSMutableDictionary *result = [NSMutableDictionary dictionary];
        NSArray *parameters = [queryString componentsSeparatedByString:@"&"];
        for (NSString *parameter in parameters)
        {
            NSArray *parts = [parameter componentsSeparatedByString:@"="];
            if ([parts count] > 1)
            {
                NSString *key = [parts[0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                NSString *value = [parts[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                result[key] = value;
            }
        }
        return result;
    }
    

    This doesn’t strip the % characters from the values, but you can do that either with

    NSString *value = [[value substringToIndex:[value length] - 1] substringFromIndex:1];
    

    Or with something like

    NSString *value = [value stringByReplacingOccurencesOfString:@"%" withString:@""];
    

    UPDATE: As of iOS 8+ theres a built-in class called NSURLComponents that can automatically parse query parameters for you (NSURLComponents is available on iOS 7+, but the query parameter parsing feature isn’t).

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

Sidebar

Related Questions

Hey I am looking for a way to replace an element value with another.
hey guys im looking for a way to show all mp3 files in a
hey guys im really frustrated im looking for a way to retrieve back my
Hey, I'm writing a personal bookmarking application, and looking for a way to keep
Hey folks. I'm looking for the best way to do something simple in symfony.
Hey all, looking to see if theres a way to easily include external html
Hey, I'm looking for the most efficient way to maintain an object relative auto-incrementing
Hey, been looking for a while but I can't seem to find any info
Hey I am looking for a way to do search in our application written
hey :) ok im looking for a way to create a large number 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.