c# - linq 和字符串数组

标签 c# linq

var result=list.select(element=>element.split['_']).list();
/* I want to extract the part of the file name from a list of file names */

我有一个文件名数组,我想从数组中提取每个文件名的部分名称

例子:

0-policy001_Printedlabel.pdf
1-policy002_Printedlabel.pdf
2-policy003_Printedlabel.pdf
3-policy004_Printedlabel.pdf

现在我想使用 Linq 从上面的数组中提取一个数组,它只给我

policy001,policy002,policy003,policy004

你能帮帮我吗?我是 lambda 表达式的新手。

最佳答案

List<string> output = fileList.Select(fileName => fileName.Split(new char[] {'-','_'})[1]).ToList()

关于c# - linq 和字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882024/

相关文章:

c# - 在表达式中插入节点/属性

c# - 使用 Entity Framework 创建动态查询

c# - Linq/Lambda 代码适用于 vb 但不适用于 c#

c# - Shellsort,2.48^(k-1) vs Tokuda 的序列

c# - 这个 LINQ 查询有什么问题?

c# - 如何从列表 linq C# 的列表中获取列表 <string>

.net - Sqlinq从linq创建sql查询的替代方法

c# - 为什么sql server查询有返回结果而linq查询没有

C# - 传递自身对象的继承方法

c# - 读取文件的最有效方式