gpt4 book ai didi

c# - 要列出的字符串。它的工作方式不同吗?

转载 作者:行者123 更新时间:2023-11-30 15:14:29 25 4
gpt4 key购买 nike

为了在 PC 上快速查找文件,我长期以来一直在使用该库 - https://github.com/VladPVS/FastSearchLibrary

    public static string _keywords = "TestFile, .rar, .zip, .mp3, Bloody6, Artificial";        
public void TestSe()
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
List<string> keywords = _keywords.Split(',').ToList(); // #2 <--------

//List<string> keywords = new List<string>() {
// @"TestFile",
// @".rar",
// @".zip",
// @".mp3",
// @"Bloody6",
// @"Artificial" }; // #1 <----------

List<string> folders = new List<string>();
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady)
{
string driveRoot = drive.RootDirectory.FullName;
folders.Add(driveRoot);
}
}
searcher = new FileSearcherMultiple(folders, (f) =>
{
foreach (var keyword in keywords)
if (f.Name.Contains(keyword))
return true;
return false;
}, tokenSource);

List<FileInfo> files = new List<FileInfo>();

searcher.FilesFound += (sndr, arg) =>
{
lock (locker)
{
arg.Files.ForEach((f) =>
{
files.Add(f);

new Thread(() =>
{
//my work
}).Start();
});
}
};

searcher.SearchCompleted += (sndr, arg) =>
{
//ended
};
searcher.StartSearchAsync();
}

我决定在全局字符串中显示关键字列表(根据需要)。但由于某种原因,搜索开始变得迟钝。如果你像#1那样直接使用这个列表,那么它会根据3000+条关键字找到所有文件。如果您使用#2,它会通过关键字“Bloody6”、“Artifical”找到 4-5 个文件。可能是什么问题?

最佳答案

很可能是因为如果您使用 _keywords.Split(',') 它将返回带空格的扩展名:

例如[space].rar, [space].zip, [space].mp3

您需要修剪这些值:

_keywords.Split(',').Select(s => s.TrimStart()).ToList();

关于c# - 要列出的字符串。它的工作方式不同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54564565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com