winform实现逐行读取并对读取内容做修改 修改要求如下:
1.去除TXT文件的信息:
文件头:DIRECTORY OF U.S. EXPORTERS,
文件尾:Copyright PIERS Directories is a trade of UBM Global Trade. PIERS Directories reports are provided for the exclusive use of our clients in accordance with our purchase
agreement. They may not be sold or released for the benefit of a third party.UBM Global Trade 2 Penn Plaza East, 12th Floor 975 Raymond Blvd, Newark, NJ 07105. Page 1 2,添加CompanyName关键字[CompanyName:]:
读到Exports TEUs:关键字后,在行开头添加CompanyName;3,添加Address关键字[Address:]:
读到Exports TEUs:关键字后,在下一行的开头添加Address;
1.去除TXT文件的信息:
文件头:DIRECTORY OF U.S. EXPORTERS,
文件尾:Copyright PIERS Directories is a trade of UBM Global Trade. PIERS Directories reports are provided for the exclusive use of our clients in accordance with our purchase
agreement. They may not be sold or released for the benefit of a third party.UBM Global Trade 2 Penn Plaza East, 12th Floor 975 Raymond Blvd, Newark, NJ 07105. Page 1 2,添加CompanyName关键字[CompanyName:]:
读到Exports TEUs:关键字后,在行开头添加CompanyName;3,添加Address关键字[Address:]:
读到Exports TEUs:关键字后,在下一行的开头添加Address;
替换的规则是什么,关键字是常量还是变量?
using System.IO;
StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径
string rowstring = "";
while (sr.Peek() > 0)
{
rowstring = sr.ReadLine();// 获取当前行字符串
//判断当前行是否有要替换的字符串即替换操作
}
sr.Close();