C#将.lst文件转换为数组
我有一个.lst文件。看起来像这样。但是我认为有一种更好、更快、更简单的方法来导入.lst文件。因为excel可以导入它,所以可能在c#中也可以 如何将.lst文件获取到c#中的数组中?它看起来像excel表格 *DXF Dateiname Funktionsmer Blattnummer Benenung DXFO0001.dxf 114D197甲板01甲板架C#将.lst文件转换为数组,c#,arrays,performance,list,C#,Arrays,Performance,List,我有一个.lst文件。看起来像这样。但是我认为有一种更好、更快、更简单的方法来导入.lst文件。因为excel可以导入它,所以可能在c#中也可以 如何将.lst文件获取到c#中的数组中?它看起来像excel表格 *DXF Dateiname Funktionsmer Blattnummer Benenung DXFO0001.dxf 114D197甲板01甲板架 DXFO0002.dxf 114D197 G72 01 DXFO0003.dxf 114I197 BL 01 DXFO0004.dxf
DXFO0002.dxf 114D197 G72 01
DXFO0003.dxf 114I197 BL 01
DXFO0004.dxf 114I197 BL 02* 通常情况下,文件要大得多,我只是发布了这个小部分进行测试 我可以将文件导入excel 因此,我认为可以将带有c#的.lst文件导入数组。我知道如何用c语言获取文件,就像微软的这个函数一样
using System;
using System.IO;
using System.Collections;
public class RecursiveFileProcessor
{
public static void Main(string[] args)
{
foreach(string path in args)
{
if(File.Exists(path))
{
// This path is a file
ProcessFile(path);
}
else if(Directory.Exists(path))
{
// This path is a directory
ProcessDirectory(path);
}
else
{
Console.WriteLine("{0} is not a valid file or directory.", path);
}
}
}
// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
Console.WriteLine("Processed file '{0}'.", path);
}
}我相信您正在寻找CSV到数组的代码?是您可能需要的东西。类似这样的东西:
public string[][] ProcessFile(string fileName)
{
var lines = File.ReadAllText(fileName).Split(new [] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
// skip first line
return lines.Skip(1).Select(line => line.Split(new[] {" "},
StringSplitOptions.RemoveEmptyEntries)).ToArray();
}
粘贴的C#cod eyou是关于列出目录的,而不是关于解析和.lst文件(在我看来像CSV文件)你的问题到底是什么?@ernodeweard如何将.lst文件放到C#中的数组中?它看起来像excel表格。你能用记事本打开文件吗?共享其中的一部分吗?@ALOISG文件的数据是斜体的。我想要一个二维数组。这很好,但只是一个一维数组。我需要一个二维数组字符串[][](像excel表格),我只是用我的代码编写的。多谢各位