比如我有一個輸入:(重複兩次)"Test your Internet connection bandwidth. Test your Internet connection bandwidth."
,我想搜索字符串互聯網和帶寬。查找使用正則表達式兩個字符串以任意順序
string keyword = tbSearch.Text //That holds value: "internet bandwidth"
string input = "Test your Internet connection bandwidth. Test your Internet connection bandwidth.";
Regex r = new Regex(keyword.Replace(' ', '|'), RegexOptions.IgnoreCase);
if (r.Matches(input).Count == siteKeyword.Split(' ').Length)
{
//Do something
}
這不工作的原因找到2「互聯網」和2個「帶寬」,所以算4,但關鍵詞長度爲2。所以,我能做些什麼?
如果你只是想搜索「互聯網」和「帶寬」你爲什麼要使用這個複雜的代碼?你還想做更多的事嗎? – Schaliasos
我剛在這個例子中使用了2個關鍵字,他可以給更多 – a1204773
你想做什麼?檢查輸入字符串中的所有關鍵字? –