问题描述
所以我一直在自己做任务。我开始做这个测试,我知道如何解决除了读取和存储之外的每个部分。每当我有这样的任务时,它们只是由换行符或制表符分隔,但在这里两者兼而有之。这是文本文件的样子:
# 01 15 // Each new day is marked with a # and then we have the date next to it They are separated by tabulators. Galagonya Alfonz OXXXXXX // In a new line we the name and other information which is not relevant here. They are separated by tabulators
我阅读了一些可以阅读它们并用开关将它们分开的论坛,但我没有设法使其正常工作。它未能存储所有数据。它要么存储奇数天,要么存储偶数天。
struct Data
{
public string New_Day_Marker;
public string Month; // I know I'm not supposed to store them as a string but if I tried to convert them it gave me a formatting error.
public string Day;
public string Name;
public string Was_There;
}
static void Main(string[] args)
{
List<Data> Lista = new List<Data>();
Data seged = new Data();
string sor;
int index = 0;
StreamReader sr = new StreamReader("naplo.txt");
while (!sr.EndOfStream)
{
sor = sr.ReadLine();
switch (index % 2 )
{
case 0:
seged.New_Day_Marker = (sor.Split(' ')[0]);
seged.Month = (sor.Split()[1]);
seged.Day = (sor.Split()[2]);
break;
case 1:
seged.Name=(sor.Split(' ')[0]);
seged.Was_There = (sor.Split()[1]);
break;
}
switch (index % 3)
{
case 0:
seged.New_Day_Marker = (sor.Split(' ')[0]);
seged.Month = (sor.Split()[1]);
seged.Day = (sor.Split()[2]);
break;
case 1:
seged.Name = (sor.Split(' ')[0]);
seged.Was_There = (sor.Split()[1]);
break;
}
if (index % 3 == 1)
Lista.Add(seged);
index++;
}
我是自学的,因为我们已经有一年没有老师了,所以请理解。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)