求助:格式转换问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
namespace CoordinateChange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string rtkFileName = string.Empty;
string datFileName = string.Empty;
private void buttonOpenRTKFile_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textBoxRtkFileName.Text = this.openFileDialog1.FileName;
rtkFileName = this.openFileDialog1.FileName;
}
}
private void buttonConvertScs_Click(object sender, EventArgs e)
{
if (rtkFileName == string.Empty || this.saveFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
this.textBoxDatFileName.Text = this.saveFileDialog1.FileName;
this.datFileName = this.saveFileDialog1.FileName;
StreamReader streamReader = new StreamReader(rtkFileName, System.Text.Encoding.Default);
StreamWriter streamWriter = new StreamWriter(datFileName, false, System.Text.Encoding.Default);
//streamWriter.AutoFlush = true;
char[] split = new char[] { '\t', ' ', ',' };
string[] colStr;
int count = 0; //计算读取文件中总的行数
while (!streamReader.EndOfStream)
{
colStr = streamReader.ReadLine().Split(split);
if (colStr.Length == 5)
{
count++;
}
}
streamReader.BaseStream.Position = 0;
streamWriter.WriteLine(count);
while (!streamReader.EndOfStream)
{
colStr = streamReader.ReadLine().Split(split);
if (colStr.Length == 5)
{
//streamWriter.WriteLine(colStr[0]+","+colStr[3]+","+colStr[2]+","+colStr[4]);
streamWriter.WriteLine(colStr[0]);
streamWriter.WriteLine(colStr[3]);
streamWriter.WriteLine(colStr[2]);
streamWriter.WriteLine(colStr[4]);
streamWriter.WriteLine();
}
}
streamReader.Close();
streamWriter.Close();
}
}
}
源文件A格式为:
L0 0000000 557.146 680.298 966.984
L1 0000000 9464.079 839.310 969.298
L2 0000000 462.461 840.370 969.247
L3 0000000 467.497 858.105 969.987
L4 0000000 469.736 858.497 970.008
L5 0000000 475.176 873.267 970.722
A转换后的格式为B:
6
L0
680.298
557.146
966.984
L1
839.310
464.079
969.298
L2
840.370
462.461
969.247
L3
858.105
467.497
969.987
L4
858.497
469.736
970.008
L5
873.267
475.176
970.722
现在如何再把B格式的文件再转换成A格式文件?请高手给与帮助,谢谢