首页 > 解决方案 > 字符串之间的最佳匹配

问题描述

我在寻找匹配字符串的解决方案时遇到了问题,因此如果有的话,我们可以获得可能的匹配。

使用包含username如下内容的字符串,

    string email = "johndoe@smo.co";
    string username = "johndoe";
    //username could be john.doe or johnd

将用户名与fullRes字符串匹配以查找用户是否存在于字符串中

string fullRes = "John Doey\nMr.Django P\nSharif Khan";
string[] wrds = fullRes.Split(new[] { "\r\n", "\r", "\n"},StringSplitOptions.None);

现在关于wrds,我已经使用过,.contains但它不起作用。

foreach(var s in wrds){
    string[] w = s.Split();
    bool isPossibleMatchName1 = username.contains(w[0]);
    bool isPossibleMatchName2 = username.contains(w[1]);
}

//given method will work on 
//string fullRes = "john doe\nMr.Django P\nSharif Khan";

我试图找到可以找到可能匹配项的解决方案。

如果有人可以帮助我将非常感激。

标签: c#regex

解决方案


推荐阅读