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;
            }
         
        }  
    }
}
相关推荐
持续前进的奋斗鸭27 分钟前
Postman测试学习(1)
学习·postman
wind_one136 分钟前
STM32[笔记]--1.前置准备
笔记·stm32·单片机
hello kitty w44 分钟前
Python学习(7) ----- Python起源
linux·python·学习
一叶知秋秋1 小时前
python学习day39
人工智能·深度学习·学习
永日456701 小时前
学习日记-day24-6.8
开发语言·学习·php
安和昂1 小时前
【iOS】 Block再学习
学习·ios·cocoa
pop_xiaoli1 小时前
OC学习—命名规范
学习·ios
jackson凌1 小时前
【Java学习笔记】String类(重点)
java·笔记·学习
行云流水剑1 小时前
【学习记录】在 Ubuntu 中将新硬盘挂载到 /home 目录的完整指南
服务器·学习·ubuntu
vijaycc2 小时前
python学习打卡day47
学习