Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-10-2010, 02:58 AM   #5 (permalink)
bitwes
Registered Member
 
Join Date: Feb 2010
Location: Cincinnati, OH
Posts: 24
Default

Quote:
Originally Posted by rahul View Post
Thanks for reply,

Can i get location of each occurrences of searched word from text
I can get searched word location but it gives me location of first occurrence of searched word within text. I want locations of all occurrences of searched word.
I wrote this C style (I guess) instr cause I like "instr" and didn't want to do this twice. returns the location of searchFor in searchIn, returns -1 when not found. You can use startingAt to iterate over the string and count the number of times one string occurs in another.

Code:
int instr(NSString *searchFor, NSString *searchIn, int startingAt){
	NSRange searchRange;
	int retVal;
	
	searchRange.location = startingAt;
	searchRange.length = [searchIn length] - startingAt;
	
	NSRange foundRange = [searchIn rangeOfString:searchFor options:0  range:searchRange];
	if(foundRange.length > 0){
		retVal = foundRange.location;
	}else{
		retVal = -1;
	}
	
	return retVal;
}
bitwes is offline   Reply With Quote
 

» Advertisements
» Online Users: 277
24 members and 253 guests
ADY, aikhan, AppAnnex, astalavista, chemistry, fkmtc, HemiMG, her-ur, ilmman, leahov, MarkC, marto1914, mer10, nicko, padsoftware, pavanindira, Raffaello, sneaky, sojourner, syver, tathaastu, timle8n1, touchcream, ziocleto
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,219
Posts: 380,710
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:32 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.