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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:49:55+00:00 2026-06-07T20:49:55+00:00

First is the code // It’s a test string NSString* aString = @,{id:\bd\,name:\ac\,latlng {lat:37.492488999999999,lng:127.014357}};

  • 0

First is the code

// It's a test string 
NSString* aString =
    @",{id:\"bd\",name:\"ac\",latlng {lat:37.492488999999999,lng:127.014357}}";
// NSString *strRegex = @"latlng:\\ \\{(\\S*?)[^}]*\\}";
NSString *strRegex = @"latlng:\\{(\\S*?)[^}]*\\}";
NSRegularExpression* regEx = [NSRegularExpression
                                          regularExpressionWithPattern:strRegex
                                                               options:0
                                                                 error:NULL];
NSArray* matches = [regEx matchesInString:dataString
                                  options:0 
                                    range:NSMakeRange(0,[dataString length])];
NSInteger num=0;
for(NSTextCheckingResult* i in matches) {
    NSRange range = i.range;
    NSUInteger index = range.location; //the index you were looking for!
    //do something here
    num++;
    NSLog(@"%i",num);
    NSLog(@"index: %d",range.location);
    NSLog(@"length: %d", range.length);
    NSLog(@"%@",[aString substringWithRange:range]);
}

When use the test string, it goes well.

My problem is when I use a string from data (its size is about 50k), it turns to the error…


edited in 2012/07/19

Below is the string occurs error

NSError *error = nil;

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.co.kr?q=%@&output=json", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//#define NSKoreanEncoding 0x80000422
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]
                                     options:kNilOptions
                                       error:&error];
NSString *dataString = [[NSString alloc] initWithData:data
                                             encoding:NSKoreanEncoding];

It can match 10 results.

And when running the substringWithRange:range line it crashes.

Below is the error log.

2012-07-19 13:31:08.792 testView[6514:11c03] index: 649
2012-07-19 13:31:08.793 testView[6514:11c03] length: 46
2012-07-19 13:31:08.793 testView[6514:11c03] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSRangeException> -[__NSCFConstantString substringWithRange:]: Range or index out of bounds
  • 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-07T20:49:57+00:00Added an answer on June 7, 2026 at 8:49 pm

    You aren’t checking that you actually got a valid range. From the class docs:

    The range {NSNotFound, 0} is returned if one of the capture groups did not participate in this particular match.

    You need to test for this condition in your code before just using the range in, e.g., substringWithRange:.

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

Sidebar

Related Questions

First code : public static int pitagoras(int a, int b) { return (int) Math.sqrt(a*a
When I run the first code and press ctrl-c immediately there will be no
Why does the first code print DCBA and the second ABCD? Is 0x44434241 not
I am trying to write some of my first code in emacs lisp and
This should be super simple. The first code block works, but when I wrap
Which one below is correct? First code has no quotes in the $_GET array
I got the problem that the if-statement doesn't work. After the first code line
First my code $.getJSON(./posts/vote/ + postId + /1, null, function(result) { if (result.result ==
Code first: AssetManager mgr = DeviceListActivity.this.getApplicationContext().getAssets(); try { Log.e(Glenn:, address); FileOutputStream fout = mgr.openFd(device/device_address.txt).createOutputStream();
Code first: '''this is main structure of my program''' from twisted.web import http from

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.