| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 825 人关注过本帖
标题:求助:格式转换问题
只看楼主 加入收藏
kristytian
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-7-10
收藏
 问题点数:0 回复次数:0 
求助:格式转换问题
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格式文件?请高手给与帮助,谢谢
搜索更多相关主题的帖子: using System string 格式 public 
2008-07-10 14:25
快速回复:求助:格式转换问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012323 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved