开发者

iPhone - searching a language dictionary for a word

开发者 https://www.devze.com 2023-03-18 08:27 出处:网络
I have a German-English dictionary of 5-6mb. 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\

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

精彩评论

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