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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:35:55+00:00 2026-05-25T02:35:55+00:00

Im trying to replace the 7th index of the array lines2. The NSMUTABLEARRAY lines2

  • 0

Im trying to replace the 7th index of the array “lines2”. The NSMUTABLEARRAY “lines2” is derived from the UNIX command “ps aux”, and I suspect that this command returns an array of NSCFStrings. Im basically trying to replace “Ss” with “Ss (Running)” for now. The problem is that I get a SIGABRT error every time The program reaches the part where it tries to replace the particular array element. The code for my viewController is below.

NSLog(@"myString is :%@", myString);
int processID = [myString intValue];

NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/ps"];

arguments = [NSArray arrayWithObjects: @"aux", [NSString stringWithFormat:@"%i", processID],nil];

[task setArguments: arguments];

NSPipe *pipe;
pipe = [NSPipe pipe];
//[task setStandardOutput: pipe];
[task setStandardOutput:pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data
                               encoding: NSUTF8StringEncoding];

//  NSLog(@"%@",string);


NSArray *lines= [string componentsSeparatedByString:@"\n"];

NSString *lastline = [lines objectAtIndex:[lines count]-2];
//  NSLog(@"%@",lastline);



lines2= [lastline componentsSeparatedByString:@" "];
NSLog(@"%@",lines2);
for (int i=0; i<[lines2 count]; i++) {

    if([[lines2 objectAtIndex:i] isEqualToString:@""]){
        [lines2 removeObjectAtIndex:i];
    }

}
for (int i=0; i<[lines2 count]; i++) {

    if([[lines2 objectAtIndex:i] isEqualToString:@""]){
        [lines2 removeObjectAtIndex:i];
    }

}
for (int i=0; i<[lines2 count]; i++) {

    if([[lines2 objectAtIndex:7] isEqualToString:@"Ss"]){
        [[lines2 objectAtIndex:0] replaceObjectAtIndex:7 withObject:@"SS (Running)"];

    }
}

Any help is very much appreciated!

  • 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-25T02:35:56+00:00Added an answer on May 25, 2026 at 2:35 am

    Please look at the documentation for the method -componentsSeparatedByString:. The signature is:

    - (NSArray *)componentsSeparatedByString:(NSString *)separator
    

    Notice the return type is NSArray. This is an immutable object. You must not change it even if inspecting the returned object (say with a debugger or an NSLog) shows it to actually be mutable. You must respect the API contract. (Read the section of the link entitled “receiving mutable objects”.)

    That said, the immediate cause of your error is this line:

    [[lines2 objectAtIndex:0] replaceObjectAtIndex:7 withObject:@"SS (Running)"];
     ^^^^^^^^^^^^^^^^^^^^^^^^ This is wrong
    

    lines2 is an array of strings. [lines2 objectAtIndex: 0] is a string. Why are you sending -replaceObjectAtIndex:withObject: to it?

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

Sidebar

Related Questions

I'm trying to replace the programs that run from my startup directory with a
im trying to replace the default 'Required' message in this validator: $this->setValidator('email', new sfValidatorAnd(array(
I am trying to replace/remove this: [\ from string bump3 NSString *bump5 = [bump3
I'm trying replace the index of form elements. I have the following var test
I am trying to replace the JavaScript onclick event handler in ASP.NET that is
Hi Im trying to replace some html with Jquery, this is what I got
Trying to replace Your Price with Discount price on this page , what am
trying to replace string once and getting this error would appreciate any help. $link
I trying to replace string Resources.AppResource.Info; like this Switch(Info); Is this possible with regex?
I'm trying to append /index.html to some folder paths in a list like this:

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.