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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:35:15+00:00 2026-06-06T05:35:15+00:00

Okay, so this is a bit confusing (well to me). I have a string

  • 0

Okay, so this is a bit confusing (well to me). I have a string that has a single number I want out of it. I have surrounded this number with ‘/’ so that I will be able to get that number out of it later.

Here is how I am getting the number out of it:

if ([MYSTRING hasSuffix:@"mp"]) {
        int start = 0;
        int end = 0;
        char looking = '/';
        for(int i=0; i < MYSTRING.length; i++){
            if (looking == [MYSTRING characterAtIndex:i]) {
                if (start == 0) {
                    start = i;
                }
                else{
                    end = i + 1;
                }
            }
        }
        NSLog(@"%@", MYSTRING); //When i NSLOG here i get '2012-06-21 03:58:00 +0000/1/mp', 1 is the number i want out of the string, but this number could also change to 55 or whatever the user has
        NSLog(@"start: %i, end: %i", start, end); //When i NSLOG here i get 'start: 25, end: 28'
        NSString *number = [MYSTRING substringWithRange:NSMakeRange(start, end)];
        number = [number stringByReplacingOccurrencesOfString:@"/" withString:@""];
        if ([number intValue] > numberInt) {
            numberInt = [number intValue];
        }

It keeps crashing and the console says:

* Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘-[__NSCFString substringWithRange:]: Range or index out of bounds’
*
First throw call stack:
(0x1875d72 0x106ce51 0x1875b4b 0x184ea64 0x3a6c 0x1080713 0x1bf59 0x1bef1 0xd532e 0xd588c 0xd49f5 0x49a2f 0x49c42 0x290fe 0x1b3fd 0x17d2f39 0x17d2c10 0x17ebda5 0x17ebb12 0x181cb46 0x181bed4 0x181bdab 0x17d1923 0x17d17a8 0x18e71 0x200d 0x1f35)
libc++abi.dylib: terminate called throwing an exception

From my counting the range is within the bounds, I dont get why I am getting this error?

Any help would be appreciated.

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-06T05:35:16+00:00Added an answer on June 6, 2026 at 5:35 am

    Your NSMakeRange(start, end) should be NSMakeRange(start, end- start);

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

Sidebar

Related Questions

Okay, this question has evolved a bit, and I want to try to start
Okay...I'm really getting a bit frustrated with this. I know that this post will
Okay, if I have a html document that looks a bit like this: <div
Okay this may sound a bit weird but it is what I have to
Okay, I have done a bit of searching online and found this thread, but
Okay this one may be a bit out from left field, but I'm going
Okay, this is a bit messy: I'm using Netbeans, and I have a main
Okay so the title might sound a bit confusing, but here's what I want
Okay, this problem is a bit odd. I have an application built in VS2010
Okay, this will be a bit hard to explain, but I'll try my best.

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.