031集——文本文件按空格分行——C#学习笔记

如下图,读取每行文本,每行文本再按空格分开读取一个字符串,输出到另一个文本:

CAD环境下,代码如下:

cs 复制代码
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AcTools;
using Autodesk.AutoCAD.Geometry;
using System.IO;

namespace Acdemo
{


    public class Acdemo
    {
        [CommandMethod("xx")]
        public void Demo()
        {
            string filename = @"E:\vba\888.txt";
            string filename1 = @"E:\vba\999.txt";
            try
            {
                File.Delete(filename1); 
            string[] contents = File.ReadAllLines(filename);
            List<List<string>> list = new List<List<string>>();
            for (int i = 0; i < contents.Length; i++)
            {
                string[] cont = contents[i].Split(new char[] { ' ' });
                List<string> sublist = new List<string>();
                for (int j = 0; j < cont.Length; j++)
                {
                    sublist.Add(cont[j]);
                    File.AppendAllLines(filename1, cont);

                }
                list.Add(sublist);
            }

            }
            catch (System.Exception)
            {

                throw;
            }
         
        }  
    }
}
相关推荐
冷雨夜中漫步4 小时前
Python快速入门(6)——for/if/while语句
开发语言·经验分享·笔记·python
盐焗西兰花5 小时前
鸿蒙学习实战之路-Reader Kit修改翻页方式字体大小及行间距最佳实践
学习·华为·harmonyos
暖馒5 小时前
Modbus应用层协议的深度剖析
网络·网络协议·c#·wpf·智能硬件
QiZhang | UESTC5 小时前
学习日记day76
学习
久邦科技5 小时前
20个免费电子书下载网站,实现电子书自由(2025持续更新)
学习
Gain_chance6 小时前
34-学习笔记尚硅谷数仓搭建-DWS层最近一日汇总表建表语句汇总
数据仓库·hive·笔记·学习·datagrip
Gain_chance7 小时前
36-学习笔记尚硅谷数仓搭建-DWS层数据装载脚本
大数据·数据仓库·笔记·学习
肖永威7 小时前
macOS环境安装/卸载python实践笔记
笔记·python·macos
XH华7 小时前
备战蓝桥杯,第九章:结构体和类
学习·蓝桥杯
暗光之痕8 小时前
Unreal5研究笔记 Actor的生命周期函数
笔记·unreal engine