Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
iTunes Match data usage and your teen tiresias314 iCloud and Apple Services 9 Mar 18, 2012 11:23 AM
Regular expressions / pulling string from inside a string dusker iPhone/iPad Programming 8 Jul 22, 2009 05:48 AM
Regular expression in java in String class Nobita Mac Programming 1 Mar 22, 2009 05:35 AM
grep, regular expressions, HTML files wrldwzrd89 Mac Programming 1 Aug 3, 2006 07:49 PM
Help with regular expressions simX OS X 3 Jul 2, 2006 05:59 PM


All times are GMT -5. The time now is 07:47 AM.

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

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