塞纳里奥信息和输出,我公司正在改变,以新的应用系统,下面的文字是由旧的应用程序 生成我需要提取信息,我们的外部会计厂商C#中提取文本文件要求与声明
Name computer name/IP address time profit
Lynn PC2/192.168.100.45 1604 5000
Kathy PC3/192.168.100.46 1700 8500
Mike PC6/192.168.100.49 1650 8400
Luke PC8/192.168.100.51 1600 11500
与像
Set account lynn PC2 from 192.168.100.45 1604 5000 to acc0001
Set account Kathy PC3 from 192.168.100.46 1700 8500 to acc0002
Set account Mike PC6 from 192.168.100.49 1650 8400 to acc0005
Set account Luke PC8 from 192.168.100.51 1600 11500 to acc0007
结果是否可以使用C#编程刚做?
目前这是我对编码的初步想法。但我怀疑它的作用,因为它可能需要超载和标题。
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
using (StreamReader sr = new StreamReader(@"C:\temp\Test.txt"))
{
string line(name, computer, IP_ADD, time, Profit);
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
public static void WriteToFile()
{
using (StreamWriter sw = File.CreateText(@"c:\temp\EResult.txt"))
{
sw.WriteLine("Please find the below generated table of 1 to 10");
sw.WriteLine("");
for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10; j++)
{
sw.WriteLine();
}
sw.WriteLine("");
}
Console.WriteLine("successfully written on file.");
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
编辑你的代码告诉我,你有一个方法在另一个方法中,并且catch语句不在正确的位置 –
line()在做什么魔术? –
这是真的c#或只是看起来像c#的随机代码? – Gusman