开发者

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 'searc开发者_StackOverflowh' would be found in strings Two and Three, but not One?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜