我有一个字符串,其中包含我需要匹配的单词,如下所示,它是常量,另一个可以更改的字符串可能包含来自该字符串 's' 的单词。
string s = "run fun play game do work click type";
string g = "he will be running. He is playing a game by clicking the mouse";
Run Code Online (Sandbox Code Playgroud)
我希望能够匹配这些单词并使它们在 Windows 窗体应用程序文本框中加粗。像run和Running匹配所以跑步会变成粗体等等。:-/ 有任何想法吗??
我会做的是使用词干分析器(例如波特词干分析器),使用 split(' ') 拆分字符串并遍历每个字符串。比较两个词的词干版本,然后将匹配的词加粗。
foreach (string t1 in term1.split(' '){
foreach (string t2 in term2.split(' '){
if (Stemmer.Stem(t1).equals(Stemmer.Stem(t2)){
//do whatever here
}
}
}
Run Code Online (Sandbox Code Playgroud)
在包含源代码的搬运工词干分析器上:
http://tartarus.org/martin/PorterStemmer/
| 归档时间: |
|
| 查看次数: |
2727 次 |
| 最近记录: |