iOS Index of Substring

MaDDaemoN

macrumors newbie
Original poster
Dec 1, 2009
3
0
Hello, im a java developer, now trying to learn objective c. I got one problem while developing app. The concept of app is to download some html page and to parse values from tables.

On java it is easy to parse some substring:


Code:

You must Login or Register to view and contribute code! This is done to increase participation in helping one another out, if you have been helped please pass on the favor.
view plaincopy to clipboardprint?
Code:
s="<td>Hello world</td>";   
s=s.substring(s.indexOf("<td>")+4);   
s=s.substring(0,s.indexOf("</td>"));
So string s will contain Hello World.

But i did not find such method as substring in NSString class.
How can i do such task in Ob-C?
 

MaDDaemoN

macrumors newbie
Original poster
Dec 1, 2009
3
0
I`ve read Cocoa string article already, but i did not find it helpfull. NSScanner also does not provide claimed functionality.
 

bredell

macrumors regular
Mar 30, 2008
127
1
Uppsala, Sweden
NSScanner also does not provide claimed functionality.
Code:
NSString *html = @"<td>Hello world!</td>";
NSString *substring;
	
NSScanner *scanner = [[NSScanner alloc] initWithString:html];
[scanner scanUpToString:@"<td>" intoString:nil];
[scanner scanString:@"<td>" intoString:nil];
[scanner scanUpToString:@"</td>" intoString:&substring];
	
NSLog(@"Found string '%@'", substring);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.