Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 13, 2009, 08:56 PM   #1
djcraze
macrumors regular
 
Join Date: Jul 2007
Regular Expression String Matching.

Basically I want to run an NSURLConnection and as data is being sent, run a Regular Expression match on it to see if the data contains a websites <title></title> brackets. If it does contain it, use a regular expression match to grab the sites title and put it into an NSString.

I know how to do regular expressions in other languages, and I know the basic syntax.. I just don't know how to apply my knowlege to Objective-C.. :-\. I pretty much hopped from PHP to Objective-C without any prior knowlege of C.

Thanks in advance!
Kyle

Last edited by djcraze; Apr 13, 2009 at 08:57 PM. Reason: spelling correction
djcraze is offline   0 Reply With Quote
Old Apr 13, 2009, 10:35 PM   #2
djcraze
Thread Starter
macrumors regular
 
Join Date: Jul 2007
After fiddling for awhile, I came up with this for anyone who cares.
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
	NSString *stringFromData = [NSString stringWithCString:[theData bytes] length:[theData length]];
	stringFromData = [stringFromData lowercaseString];
	NSRange beforeTitle = [stringFromData rangeOfString:@"<title>"];
	NSRange afterTitle = [stringFromData rangeOfString:@"</title>"];
	NSRange myRange = NSMakeRange((beforeTitle.location + (int)7), (afterTitle.location - beforeTitle.location - (int)7));
	NSString *afterString = [stringFromData substringWithRange:myRange];
	NSLog(@"%@",afterString);
}
djcraze is offline   0 Reply With Quote
Old Dec 4, 2010, 03:49 AM   #3
kingthong
macrumors member
 
Join Date: Sep 2010
Location: Somewhere but not here.
Quote:
Originally Posted by djcraze View Post
After fiddling for awhile, I came up with this for anyone who cares.
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
	NSString *stringFromData = [NSString stringWithCString:[theData bytes] length:[theData length]];
	stringFromData = [stringFromData lowercaseString];
	NSRange beforeTitle = [stringFromData rangeOfString:@"<title>"];
	NSRange afterTitle = [stringFromData rangeOfString:@"</title>"];
	NSRange myRange = NSMakeRange((beforeTitle.location + (int)7), (afterTitle.location - beforeTitle.location - (int)7));
	NSString *afterString = [stringFromData substringWithRange:myRange];
	NSLog(@"%@",afterString);
}
Slogged for quite a while before i came across this. million thanks!
__________________
I fought the law...and the law won.
kingthong is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Regular expression / sed question. Big Dave Mac Programming 9 Feb 26, 2014 11:51 PM
Format string is not a string literal. larswik Mac Programming 5 Jan 17, 2014 10:45 PM
Search a string for a String of a specific format. ncaissie iPhone/iPad Programming 19 Nov 15, 2013 10:42 AM
Expression is not Assignable Blakeasd Mac Programming 2 Jan 26, 2013 10:29 PM

Forum Jump

All times are GMT -5. The time now is 09:11 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC