c# - 字符串之间的最佳匹配
问题描述
我在寻找匹配字符串的解决方案时遇到了问题,因此如果有的话,我们可以获得可能的匹配。
使用包含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";
我试图找到可以找到可能匹配项的解决方案。
如果有人可以帮助我将非常感激。
解决方案
推荐阅读
- reactjs - 使用复杂/嵌套状态更新重新渲染 React 子组件
- c - 如何在 QEMU 中关闭 VBE 扩展
- .net-core - 如何在不使用 IDE 的情况下指定 dotnet 控制台应用程序图标?
- google-apps-script - 在 Google Workspace 插件中获取工作表和幻灯片编辑器事件对象时出现问题
- java - 无法从列表视图中获取项目位置:尝试在空对象引用上调用虚拟方法...
- c - 编写使用位运算符、相等检查和布尔运算符的表达式,在 O(1) 时间内完成以下操作
- python - 模块“django.template”没有属性“resolve_variable”
- excel - 代码重构,将单元格从一张纸移动到另一张纸
- kubernetes - Kubernetes:不清楚“Host_IP”和“advertise_IP”SAN的区别
- visual-studio - 错误 C2146:语法错误:缺少“;” 在 masm Visual Studio 中的标识符“SEGMENT”之前