eric.mitchell
eric.mitchell

Reputation: 8855

Search NSString in line from file

Is it possible to make a function that searchs a string for an exact substring so that it will only 'return true' if the exact string if found, not as part of a larger word?

NSString* search = @"tele";
NSString* stringOne = @"telephone";
NSString* stringTwo = @"tele phone";
NSString* stringThree = @"phone tele";

What I mean is: Is it possible to search for a string in a way that the NSString 'search' would be found in strings Two and Three, but not One?

Upvotes: 0

Views: 532

Answers (2)

Hot Licks
Hot Licks

Reputation: 47729

Simplest approach is to append blanks (or whatever your separators are) to front and rear of both strings, then do the search.

Upvotes: 1

Angela Navarro
Angela Navarro

Reputation: 44

Try using the following function in the NSString class:

- (NSRange)rangeOfString:(NSString *)aString

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsstring_Class/Reference/NSString.html

Upvotes: 1

Related Questions