关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。
想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。
8 个月前关闭。
Improve this question
例如名字是
现在为此我将在 C# 中创建一个 Linq 查询,例如字符串是
textString = "abdolah"
结果我期待所有这些。var data = db.TableList.where(a=>a.Name.Contains(textString).ToList();
所以问题是如何或是否有任何内置库用于比较 .Net 中的名称
最佳答案
正如我上面所建议的,最快的入门方法是尝试我提到的库之一。
这是使用 https://github.com/JakeBayer/FuzzySharp 在 2 分钟内编写的程序:
结果:
代码:
using System;
using System.IO;
using FuzzySharp;
using FuzzySharp.PreProcess;
namespace zzzzzzzz
{
internal static class Program
{
private static void Main(string[] args)
{
var referenceName = "Abdallah";
var referenceGoal = 80;
var names = @"
abdulah
abdullah
abdola
abdollah
S abdullah
abdul
aabdullah";
using (var reader = new StringReader(names))
{
while (true)
{
var line = reader.ReadLine();
if (line == null)
break;
var ratio = Fuzz.Ratio(referenceName, line, PreprocessMode.Full);
var success = ratio >= referenceGoal;
Console.Write($"Current = '{line}', Ratio = {ratio}, Result = ");
var color = Console.ForegroundColor;
Console.ForegroundColor = success ? ConsoleColor.Green : ConsoleColor.Red;
Console.Write($"{(success ? "PASS" : "FAIL")}{Environment.NewLine}");
Console.ForegroundColor = color;
}
}
}
}
}
库的 NuGet 包:https://www.nuget.org/packages/FuzzySharp/2.0.2编辑:
我在这里试过你的例子,我得到了 100%(显然)
关于c# - LINQ 搜索相似字符串(名称),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66347591/