开发者

iPhone - searching a language dictionary for a word

I have a German-English dictionary of 5-6mb.

  1. Assuming I store the German words in an array of strings, how do I get "foo", "bar foo" and "foo bar" from the following list of 'words' : "foo","foobar","bar foo","barfoo", "foo bar"

The following code is going to return them all, and if I search for " 开发者_StackOverflowfoo " I don't get "foo"

NSRange r = [word rangeOfString:@".*foo.*" options:NSRegularExpressionSearch];
if (r.location != NSNotFound) {
    NSLog(@"%@",word);
}


Try this :

^foo$

When using .*foo.*, you allow 0 or more characters (.*) before and after foo. This is why you get all the strings returned.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜