• 大小: 268KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签: C#  分割  

资源简介

C#写的文本分割器有源码,有注释。想了解的朋友可以看看。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
//win/51/aspx/
namespace WindowsFormsApplication1
{
    class CutFile
    {
        /// 
        /// 分割文件
        /// 

        /// 文件路径
        /// 分割方式
        /// 侵害参数
        /// 保存路径
        /// 保存文件名
        public static void CutFiles(string Pathstring Conditionstring Numstring SavePathstring FileName)
        {
            string FileNames = FileName.Substring(0FileName.LastIndexOf(‘.‘));
            if(Condition==“0“)
            {
                CutFileByRows(Path Num SavePath FileNames);
            }
            else
            {
                CutFileByByte(Path Num SavePath FileNames);
            }

            
        }

        /// 
        /// 按行分割文本文件
        /// 

        /// 文件路径
        /// 行数
        /// 保存路径
        /// 保存文件名
        private static void CutFileByRows(string Pathstring Numstring SavePathstring FileName)
        {
            int rows = 0;
            int page = 1;

            //如果文件夹存在刚删除文件夹及其子目录和文件
            if (Directory.Exists(SavePath + @“\“ + FileName + “_cutter“))
            {
                Directory.Delete(SavePath + @“\“ + FileName + “_cutter“ true);
            }
            using (StreamReader sr = new StreamReader(Path System.Text.Encoding.Default))
            {
                string line;
                System.IO.Directory.CreateDirectory(SavePath + @“\“ + FileName+“_cutter“);

                while ((line = sr.ReadLine()) != null)
                {
                    rows++;
                    string SavePaths = SavePath + @“\“ + FileName + “_cutter“ + “\\“ + FileName + “_“ + page + “.txt“;
                    StreamWriter sw= new StreamWriter(SavePaths true Encoding.Default);
                    sw.WriteLine(line);
                    sw.Close();
                    if (rows.ToString() == Num)
                    {
                        page++;
                        rows = 0;
                        StringBuilder st = new StringBuilder();
                        
                    }
                }
                
            }
        }


        /// 
        /// 按字数分割文本文件
        /// 

        /// 文件路径
        /// 字数
        /// 保存路径
        /// 保存文件名
        private static void CutFileByByte(string Path string Num string SavePath string FileName)
        {
            string Str = File.ReadAllText(Path Encoding.Default);
            Int64 Count = Str.Length;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2045  2009-06-25 16:34  TextCutter\51aspx源码必读.txt

     文件       4485  2009-05-22 08:03  TextCutter\from.gif

     文件       4286  1999-01-01 01:06  TextCutter\TextCutter\2009062202104796.ico

     文件       4286  1999-01-01 01:05  TextCutter\TextCutter\20090622022017410.ico

     文件       4286  1999-01-01 01:06  TextCutter\TextCutter\bin\Debug\app.publish\Application Files\WindowsFormsApplication1_1_0_0_0\2009062202104796.ico.deploy

     文件       4286  1999-01-01 01:05  TextCutter\TextCutter\bin\Debug\app.publish\Application Files\WindowsFormsApplication1_1_0_0_0\20090622022017410.ico.deploy

     文件      27136  1999-01-01 01:08  TextCutter\TextCutter\bin\Debug\app.publish\Application Files\WindowsFormsApplication1_1_0_0_0\WindowsFormsApplication1.exe.deploy

     文件       7568  1999-01-01 01:08  TextCutter\TextCutter\bin\Debug\app.publish\Application Files\WindowsFormsApplication1_1_0_0_0\WindowsFormsApplication1.exe.manifest

     文件         45  1999-01-01 01:08  TextCutter\TextCutter\bin\Debug\app.publish\autorun.inf

     文件     475576  1999-01-01 01:08  TextCutter\TextCutter\bin\Debug\app.publish\setup.exe

     文件       5405  1999-01-01 01:08  TextCutter\TextCutter\bin\Debug\app.publish\WindowsFormsApplication1.application

     文件       1650  2009-06-25 16:43  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.application

     文件      27648  2009-06-25 16:43  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.exe

     文件       3900  2009-06-25 16:43  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.exe.manifest

     文件      42496  2009-06-25 16:43  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.pdb

     文件       1650  1999-01-01 02:16  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.vshost.application

     文件      14328  2009-06-25 16:32  TextCutter\TextCutter\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件       4687  2009-06-25 16:42  TextCutter\TextCutter\CutFile.cs

     文件       6460  2009-06-25 16:43  TextCutter\TextCutter\Form1.cs

     文件      18867  2009-06-25 16:43  TextCutter\TextCutter\Form1.Designer.cs

     文件      12958  2009-06-25 16:43  TextCutter\TextCutter\Form1.resx

     文件       1023  2009-06-25 16:32  TextCutter\TextCutter\obj\Debug\TextCutter.csproj.FileListAbsolute.txt

     文件        847  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\TextCutter.csproj.GenerateResource.Cache

     文件       1650  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.application

     文件       1961  2009-06-25 16:32  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        847  1999-01-01 01:06  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件      27648  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.exe

     文件       3900  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.exe.manifest

     文件       4852  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件      42496  2009-06-25 16:43  TextCutter\TextCutter\obj\Debug\WindowsFormsApplication1.pdb

............此处省略27个文件信息

评论

共有 条评论