我试图弄清楚从字典文件到给定字符串中识别英语单词的最佳匹配问题.
例如("lines"是字典单词列表):
string testStr = "cakeday";
for (int x= 0; x<= testStr.Length; x++)
{
string test = testStr.Substring(x);
if (test.Length > 0)
{
string test2 = testStr.Remove(counter);
int count = (from w in lines where w.Equals(test) || w.Equals(test2) select w).Count();
Console.WriteLine("Test: {0} / {1} : {2}", test, test2, count);
}
}
Run Code Online (Sandbox Code Playgroud)
给出输出:
Test: cakeday / : 0
Test: akeday / c : 1
Test: keday / ca : 0
Test: eday / cak : 0
Test: day / cake : …Run Code Online (Sandbox Code Playgroud) 假设我有字符串:
10,11,12,13,14,ABC,DEF,GHI,66
我希望运行一个正则表达式反对它只返回0-9和","字符,基本上剥离其他任何东西.
我看过Regex.Replace,但有些东西不太合适.我的代码如下:
Regex reg = new Regex(@"[0-9,]+");
string input = reg.Replace(input, delegate(Match m)
{
return String.Empty;
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?