• Winform读取文档。然后创建,奇数行保存一个文档,偶数行保存一个文档


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Text.RegularExpressions;

    namespace TextModify
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void button3_Click(object sender, EventArgs e)
    {
    Product("CN");
    Product("EN");
    MessageBox.Show("生成文件成功");
    }

    private void button1_Click(object sender, EventArgs e)
    {
    FolderBrowserDialog bro = new FolderBrowserDialog();
    bro.ShowDialog();
    txtPath.Text = bro.SelectedPath;
    }

    private void button2_Click(object sender, EventArgs e)
    {
    FolderBrowserDialog bro = new FolderBrowserDialog();
    bro.ShowDialog();
    txtSavePath.Text = bro.SelectedPath;
    }

    private void Product(string Name)
    {
    string[] filenames = Directory.GetFiles(txtPath.Text);
    foreach (string files in filenames)
    {
    string strExteenstion = Path.GetExtension(files);
    string[] str = new string[] { ".txt" };
    string newPath = txtSavePath.Text + "\" + Name;
    Directory.CreateDirectory(newPath);
    if (str.Contains(strExteenstion))
    {
    string oldName = Path.GetFileName(files);
    string newCNName = Name + oldName;
    File.Create(newPath + "\" + newCNName).Close();//创建文件夹
    StreamReader srCN = new StreamReader(files, Encoding.Default);
    FileStream fsCN = new FileStream(newPath + "\" + newCNName, FileMode.Append);
    StreamWriter swCN = new StreamWriter(fsCN);
    try
    {
    int i = 1;
    string s = srCN.ReadLine();
    while (s != null)
    {
    if (i % 2 == 0)
    {
    i++;
    if (Name == "CN")
    {
    swCN.WriteLine(s);
    }
    }
    else
    {

    i++;
    if (Name == "EN")
    {
    swCN.WriteLine(s);
    }

    }
    s = srCN.ReadLine();
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("操作失败,失败原因:" + ex.Message);
    }

    finally
    {
    srCN.Close();
    swCN.Close();
    fsCN.Close();
    }
    }
    }
    }

    }
    }

  • 相关阅读:
    初识分布式计算:从MapReduce到Yarn&Fuxi
    日志的艺术(The art of logging)
    关于负载均衡的一切:总结与思考
    打印中文dict list的各种姿势
    不想再被鄙视?那就看进来! 一文搞懂Python2字符编码
    什么是分布式系统,如何学习分布式系统
    再论分布式事务:从理论到实践
    从银行转账失败到分布式事务:总结与思考
    git命令
    IntelliJ idea 中使用Git
  • 原文地址:https://www.cnblogs.com/liziqiang/p/3831910.html
Copyright © 2020-2023  润新知