gpt4 book ai didi

C# 从字符串列表中删除文件扩展名

转载 作者:太空狗 更新时间:2023-10-30 00:01:36 25 4
gpt4 key购买 nike

我的程序所做的基本上是将目录中的文件名(包括其扩展名)列出到列表框中。然后它有一个排序函数,可以将列表字符串按字母顺序排序。

最后它有一个二进制搜索功能,允许用户输入任何字符串,程序将比较并将匹配结果显示到列表框中。

现在,所有这些功能都能完美运行,但我似乎无法在搜索后删除文件名的扩展名。

例如在扫描和排序部分它列出的文件名是:filename.mp3

现在,我希望它在单击搜索按钮时执行的操作是删除文件扩展名并仅显示文件名。

    private void buttonSearch_Click(object sender, RoutedEventArgs e)
{

listBox1.Items.Clear();

string searchString = textBoxSearchPath.Text;


int index = BinarySearch(list1, 0, list1.Count, searchString);

for (int n = index; n < list1.Count; n++)
{
//Removes file extension from last decimal point ''not working''
int i = list1[n].LastIndexOf(".");
if (i > 0)
list1[n].Substring(0, i);

// Adds items to list
if (list1[n].IndexOf(searchString, StringComparison.OrdinalIgnoreCase) != 0) break;
listBox1.Items.Add(list1[n]);
}
MessageBox.Show("Done");
}

最佳答案

C# 非常简单,如果需要超过 2 分钟,there probably is a method for it在框架中。

关于C# 从字符串列表中删除文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15879457/

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