Have you considered using pull-style reads & recursive processing? That would eliminate reading the whole file into memory and also eliminate managing some own stack to keep track how deep you're parsing. Below an example in Swift. The example works with your sample "txf", but not with the dropbox version;...

I don't know why your first method didn't work. I assume you defined bodyText before that snippet. This code worked fine for me, - (void)viewDidLoad { [super viewDidLoad]; NSString *htmlData = @"This is some stuff before <body> this is the body </body> with some more stuff"; NSScanner* newScanner = [NSScanner...

Not an Objective-C expert myself, but I guess you need to assign the replaced value back to the variable: myHTMLString = [myHTMLString stringByReplacingOccurrencesOfString:@"<title>Bounty Boulevard &#187; &#187; Latest News</title>" withString:@""]; So, in general the idiomatic way to replace a string and keeping the result in the same variable is: str =...

Your mistake is simple: you have started by making a false assumption. You artificially separate the string into words: NSArray *elements = [inputString componentsSeparatedByString:@" "]; for (int i=0; i<[elements count];i++) { // scan for one number } Thus, that is exactly what happens. Each word is scanned for one number,...