【发布时间】:2011-02-24 23:34:05
【问题描述】:
我需要一些基本的帮助。
我有一个文件夹,其中有一个文件。
File中有两行,行中的数据用“//”隔开。
例子:
在@"C:\ExampleFolder_ABCD\"位置有一个文件夹
在文件夹中有一个文件@"C:\ExampleFolder_ABCD\ExampleFile_ABCD.txt"
在文件中有两行:名称_1 // 描述_1
名称_2 // 描述_2
我需要我的程序显示每行的第一部分、“//”之前的部分,并且只显示这部分。
我已经进行了一些研究,但希望得到一些实时帮助。
当然,任何帮助,无论好坏,都将不胜感激。
注意:这与作业无关。它涉及我的一个项目,它将帮助我整理我的电话簿。
洛夫罗·米尔尼克
如果您想测试,请将以下代码复制到新创建的命名空间中,编辑并执行它。
string MainDirectoryPath = @"C:\ExampleFolder_ABCD\"; // Example directory path - Completely random name (100% no overwrite)
string MainFileName = @"C:\ExampleFolder_ABCD\ExampleFile_ABCD.txt"; // Example file path - Completely random name (100% no overwrite)
Directory.CreateDirectory(MainDirectoryPath); // Create the directory.
StreamWriter CreateExampleFile = new StreamWriter(MainFileName); // Create the file.
CreateExampleFile.Close(); // Close the process.
StreamWriter WriteToExampleFile = File.AppendText(MainFileName); // Append text to the file.
WriteToExampleFile.WriteLine("Name_1 // Description_1"); // This line to append.
WriteToExampleFile.WriteLine("Name_2 // Description_2"); // This line to append.
WriteToExampleFile.Close(); // Close the process.
//
//
// I would like to know how to display both names in a list
// without the Description part of the line.
// Maybe with a command that contains "* // *" ??
【问题讨论】:
-
String.Split 应该会有所帮助,还有 TextReader(特别是 ReadLine)
标签: c# list arraylist streamreader