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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:37:19+00:00 2026-05-26T10:37:19+00:00

I have code that scans and returns NSString like this: NSString *GetText = [[NSString

  • 0

I have code that scans and returns NSString like this:

NSString *GetText = [[NSString alloc] init];
NSString *ScannedText;
NSScanner *TheScanner = [NSScanner scannerWithString:somLongString];
int start=0;
int index=0;
int ObjectCount;
char c;
for (int i = 0; i < [somLongString length] ; i++) {
    c = [somLongString characterAtIndex:i];
    if (c == '=') {
        start = i+1;
        [TheScanner setScanLocation:start];
        [TheScanner scanUpToString:@"&" intoString:&GetText];
        NSLog( @"%@",GetText);
        [UserValuesObject insertObject:GetText  atIndex:index];
        NSLog(@"%@",[UserValuesObject objectAtIndex:index]);
        index++;
    }
}

Now I want to add the GetText object I am creating each time to an array. When I try printing the first:

NSLog(@"%@",GetText); 

it works! But when I am tring to add it to the object and then print (for debug) I am getting null on each print of the log:

NSLog(@"%@",[UserValuesObject objectAtIndex:index]);

any ideas?

  • 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-26T10:37:19+00:00Added an answer on May 26, 2026 at 10:37 am

    You may not have initialized your array properly (or at all), try this (syntax improvements included):

    NSString *getText = [NSString string];
    NSScanner *scanner = [NSScanner scannerWithString:someLongString];
    NSUInteger start = 0;
    NSUInteger index = 0;
    NSMutableArray *userValuesObject = [NSMutableArray array];
    //  You should save the length of someLongString before starting the loop 
    //   so that each iteration doesn't have to call length to see if i has 
    //   reached length yet
    for (int i = 0, len = [someLongString length]; i < len; ++i) {
        if ([somLongString characterAtIndex:i] == '=') {
            [scanner setScanLocation:(i + 1)];
            [scanner scanUpToString:@"&" intoString:getText];
            NSLog(@"%@", GetText);
            [userValuesObject insertObject:getText atIndex:index];
            NSLog(@"%@", [userValuesObject objectAtIndex:index]);
            ++index;
        }
    }
    

    From NSMutableArray Docs:

    insertObject:atIndex:
    

    Parameters

    anObject – The object to add to the array’s content. This value must
    not be nil.

    Important: RaisesanNSInvalidArgumentException if anObject is nil.

    index – The index in the array at which to insert anObject. This
    value must not be greater than the count of elements in the array.

    Important: Raises an NSRangeException if index is greater than the number of elements in the array.

    If index is already occupied, the objects at index and beyond are
    shifted by adding 1 to their indices to make room. Note that NSArray
    objects are not like C arrays. That is, even though you specify a size
    when you create an array, the specified size is regarded as a “hint”;
    the actual size of the array is still 0. This means that you cannot
    insert an object at an index greater than the current count of an
    array. For example, if an array contains two objects, its size is 2,
    so you can add objects at indices 0, 1, or 2. Index 3 is illegal and
    out of bounds; if you try to add an object at index 3 (when the size
    of the array is 2), NSMutableArray raises an exception.

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

Sidebar

Related Questions

I have code that looks like this: template<class T> class list { public: class
I have code that I want to look like this: List<Type> Os; ... foreach
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query
I have a JavaFX app with a some code like this... public class MainListener
I have this WxWidgets test source code that compiles, and when run, it shows
I have code like this: // Create event handler delegate symbolReader.ReadNotify += new EventHandler(symbolReader_ReadNotify);
I have this code in a C application that's embedding Python (2.7.1): { PyObject

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.