解决方案 »
- 十万火急啊!高分求跪原因!! C# 用全局钩子时也设置成功了,但是一点窗口,窗口就莫名的关闭,求跪原因啊,
- 在打开\\MyServer\project上的项目时,警告说该位置不是Full Trusted的。
- 如何实现?????
- 如何最快速的判断本地电脑是否与远程服务器连接
- 如何实现数字的转换?急!!!
- 如何将winform中 DateTimePicker 控件中的日期部分屏蔽掉?
- Math.Round()函数的问题
- 无法新建Asp.net Web应用程序和Asp.net Web服务程序
- to zzhangroc () ,你这个人很烦。
- 控件可以删除自己吗????????
- 一个list赋值给DataSource的问题,烦请解答。
- wpf中如何实现对richtextbox中文本的逐行读取?
string[] fileLines = File.ReadAllLines("file path");
StreamWriter sw = new StreamWriter("file path", false, Encoding.UTF8);
int i = 1;
foreach (string s in fileLines)
{
string[] s2 = s.Split(',');
sw.WriteLine("J"+i+",1,"+s2[2]+","+s2[3]);
sw.Flush();
}
sw.Close();
拆分
重新拼接
这才是最重要的
然后整个粘进excel里,处理起来就方便了
处理完了,再粘回来,然后替换回逗号就行了完全没必要开发什么程序来处理这东西
每次要处理的内容不一样,逻辑就要来回来回的改,很难适用多种情况
而且只用一次,这程序没什么存在的价值
using System.IO;namespace CVSParser
{
class Program
{
public static void Main(string[] args)
{
Parser();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
public static void Parser()
{
char[] delimiters = new char[] { ',' };
using (StreamReader reader = new StreamReader("demo.txt"))
{
while (true)
{
string line = reader.ReadLine();
if (line == null)
{
break;
}
string[] parts = line.Split(delimiters);
// Console.WriteLine("{0} field(s)", parts.Length);
Console.WriteLine("J{0},{1},{2},37{3}", parts[0], 1, parts[3], parts[2]);
}
}
}
}
}
string SourcePath=textBox1.Text;
string DestinationPath = textBox2.Text; DirectoryInfo Directory = new DirectoryInfo(SourcePath); foreach (FileInfo file in Directory.GetFiles())
{
StreamReader sr = new StreamReader(SourcePath + file.Name);
string[] lines = File.ReadAllLines(SourcePath + file.Name);
int a = 0;
string Combina=""; List<string> needs = new List<string>();
foreach(string line in lines)
{
//取值
}
}
public static void WriteInTxt(string DestinationPath,List<string> needs)
{
string WriteInPath = DestinationPath;
int NumberCount =needs.Count;
int i=0; if (!File.Exists(WriteInPath))
{
FileStream fs1 = new FileStream(WriteInPath, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
for(i = 0;i < NumberCount ; i++)
{ sw.WriteLine(needs[i]);//开始写入值
}
sw.Close();
fs1.Close();
}
else
{
FileStream fs = new FileStream(WriteInPath, FileMode.Open, FileAccess.Write);
StreamWriter sr = new StreamWriter(fs);
for (i = 1; i < NumberCount; i++)
{ sr.WriteLine(needs[i]);//开始写入值 }
sr.Close();
fs.Close();
}