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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:06:19+00:00 2026-06-01T04:06:19+00:00

I have this text read into an NSString *responce which I am trying to

  • 0

I have this text read into an NSString *responce which I am trying to parse into an array.

        total:    used:    free:  shared: buffers:  cached:
Mem:  30412800 16805888 13606912        0  1581056  4837376
Swap:        0        0        0
MemTotal:        29700 kB
MemFree:         13288 kB
MemShared:           0 kB
Buffers:          1544 kB
Cached:           4724 kB
SwapCached:          0 kB
Active:           1197 kB
Inactive:          699 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:        29700 kB
LowFree:         13288 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
Mapped:            277 kB
Slab:              132 kB
CommitLimit:     14848 kB
Committed_AS:     3400 kB
PageTables:       1567 kB
VmallocTotal:  1048404 kB
VmallocUsed:     17208 kB
VmallocChunk:  1031168 kB

If I read into an array like this, I get over 300 objects in the array!

NSMutableArray *items2 = [NSMutableArray arrayWithArray:[responce componentsSeparatedByString:@" "]];
NSLog(@"count of memory array = %i",[items2 count]);

I add this to try and remove all the blank ones, but still end up with 170.

for (int i=0; i<[items2 count]; i++) {
            NSString *str = [items2 objectAtIndex:i];
            if([str length]==0 || !str || str==nil) {
                [items2 removeObjectAtIndex:i];
            }
        }

This NSLog statement tells me that most of them are zero length, why where they not removed?

for (int i=0; i<[items2 count]; i++) {
            NSLog(@"%i=%@ / length=%d",i,[items2 objectAtIndex:i],[[items2 objectAtIndex:i] length]);
        }
  • 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-01T04:06:21+00:00Added an answer on June 1, 2026 at 4:06 am

    It looks like what you really want is a NSDictionary + NSScanner:

    NSDictionary *scanString(NSString *str)
    {
        NSScanner *scanner = [NSScanner scannerWithString:str];
        NSMutableDictionary *results = [NSMutableDictionary dictionary];
    
        // read away the first three lines (headers, mem, and swap). If you need this data, parse it here.
        for (int i = 0; i < 3; i++) {
            [scanner scanUpToString:@"\n" intoString:NULL];
        }
    
        NSString *line = nil;
        while ([scanner scanUpToString:@"\n" intoString:&line]) {
            // trim the line
            line = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
            // read up to the ':'
            int loc = [line rangeOfString:@":"].location;
            NSString *key = [line substringToIndex:loc];
    
            // read the value associated with the key
            NSString *value = [[line substringFromIndex:loc + 1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            value = [value substringToIndex:[value rangeOfString:@" "].location];
    
            [results setObject:value forKey:key];
        }
    
        return results;
    }
    

    This puts it in a dictionary that you can access by using the following:

    NSDictionary *parsed = scanString(response);
    NSLog(@"Active Memory: %@", [parsed objectForKey:@"Active"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this text file that I read into a Java application and then
I have a text file, I want to read this text file into 3
I have a .txt file having some text. I want to read this file
I am trying to import data into rails (3.1) and I have created this
I have this code to read in a text file, with words separated by
I have a small text file that I'd like to read into a scalar
I have servlet deployed in JBoss. I want to read/write data into a text
I have this RTF text: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}} {\colortbl ;\red0\green0\blue0;\red255\green0\blue0;} \viewkind4\uc1\pard\qc\cf1\fs16 test \b bold \cf2\b0\i
I have this little text <div> Hello world<br> this is a good<br> text! <br><br>
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on

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.