zoukankan      html  css  js  c++  java
  • TXT插入者批量随机插入代码

    private void btn_PLEnglishSingleInsert_Click(object sender, EventArgs e)
    {
        if ((this.txtb_FolderIn.Text == string.Empty) || !Directory.Exists(this.txtb_FolderIn.Text))
        {
            MessageBox.Show("批量插入的文件夹路径错误!");
        }
        else if ((this.txtb_FolderOut.Text == string.Empty) || !Directory.Exists(this.txtb_FolderOut.Text))
        {
            MessageBox.Show("批量输出的文件夹路径错误!");
        }
        else
        {
            spin spin = new spin();
            string contents = "";
            if (this.cb_Subfolder.Checked)
            {
                foreach (string str2 in Directory.GetDirectories(this.txtb_FolderIn.Text))
                {
                    DirectoryInfo info = new DirectoryInfo(str2);
                    foreach (FileInfo info2 in info.GetFiles("*.txt"))
                    {
                        using (StreamReader reader = info2.OpenText())
                        {
                            string str3;
                            int num3;
                            int num4;
                            Random random;
                            int num6;
                            int length = 0;
                            int index = 0;
                            bool flag = false;
                            if ((this.txtb_FolderIn.Text == string.Empty) || !Directory.Exists(this.txtb_FolderIn.Text))
                            {
                                MessageBox.Show("批量插入的文件夹路径错误!");
                            }
                            else if ((this.txtb_FolderOut.Text == string.Empty) || !Directory.Exists(this.txtb_FolderOut.Text))
                            {
                                MessageBox.Show("批量输出的文件夹路径错误!");
                            }
                            else if (this.txtb_Keywords.Text == string.Empty)
                            {
                                MessageBox.Show("输入不完全, 请填写完整!");
                            }
                            else if ((this.txtb_RandomTime.Text == string.Empty) && this.rb_PartIn.Checked)
                            {
                                MessageBox.Show("输入不完全, 请填写完整!");
                            }
                            else
                            {
                                str3 = reader.ReadToEnd();
                                num3 = str3.Length;
                                num4 = 0;
                                random = new Random(DateTime.Now.Second);
                                for (int j = 0; j < str3.Length; j++)
                                {
                                    if (str3[j] == ' ')
                                    {
                                        flag = true;
                                    }
                                }
                                if (!flag)
                                {
                                    MessageBox.Show("文章内无空格, 非法");
                                }
                                else
                                {
                                    if (!this.rb_PartIn.Checked)
                                    {
                                        goto Label_0508;
                                    }
                                    num6 = int.Parse(this.txtb_RandomTime.Text);
                                    if (num6 <= this.txtb_Keywords.Lines.Length)
                                    {
                                        goto Label_03DA;
                                    }
                                    MessageBox.Show("插入个数不能小于插入内容栏内项的个数, 请重新输入!");
                                }
                            }
                            return;
                        Label_025A:
                            length = random.Next(3, num3 - 2);
                            if ((str3[length - 1] == ' ') && (str3[length] == ' '))
                            {
                                index++;
                                num4 = random.Next(num6 + 1, num6 + 100);
                                str3 = str3.Substring(0, length) + spin.Spinner(this.txtb_Keywords.Lines[num4 % this.txtb_Keywords.Lines.Length], num4) + str3.Substring(length);
                            }
                            else if (str3[length - 1] == ' ')
                            {
                                if (str3[length - 3] != '<')
                                {
                                    index++;
                                    num4 = random.Next(num6 + 1, num6 + 100);
                                    str3 = str3.Substring(0, length) + spin.Spinner(this.txtb_Keywords.Lines[num4 % this.txtb_Keywords.Lines.Length], num4) + " " + str3.Substring(length);
                                }
                            }
                            else if ((str3[length + 1] == ' ') && (str3[length - 1] != '<'))
                            {
                                index++;
                                num4 = random.Next(num6 + 1, num6 + 100);
                                str3 = str3.Substring(0, length + 1) + " " + spin.Spinner(this.txtb_Keywords.Lines[num4 % this.txtb_Keywords.Lines.Length], num4) + str3.Substring(length + 1);
                            }
                        Label_03DA:
                            if (index < num6)
                            {
                                goto Label_025A;
                            }
                            goto Label_051C;
                        Label_03E8:
                            length = random.Next(3, num3 - 2);
                            if ((str3[length - 1] == ' ') && (str3[length] == ' '))
                            {
                                str3 = str3.Substring(0, length) + spin.Spinner(this.txtb_Keywords.Lines[index], length) + str3.Substring(length);
                                index++;
                            }
                            else if (str3[length - 1] == ' ')
                            {
                                if (str3[length - 3] != '<')
                                {
                                    str3 = str3.Substring(0, length) + spin.Spinner(this.txtb_Keywords.Lines[index], length) + " " + str3.Substring(length);
                                    index++;
                                }
                            }
                            else if ((str3[length + 1] == ' ') && (str3[length - 1] != '<'))
                            {
                                str3 = str3.Substring(0, length + 1) + " " + spin.Spinner(this.txtb_Keywords.Lines[index], length) + str3.Substring(length + 1);
                                index++;
                            }
                        Label_0508:
                            if (index < this.txtb_Keywords.Lines.Length)
                            {
                                goto Label_03E8;
                            }
                        Label_051C:
                            contents = str3;
                            string path = "";
                            for (int i = this.txtb_FolderIn.Text.Length + 1; i < str2.Length; i++)
                            {
                                path = path + str2[i];
                            }
                            new DirectoryInfo(this.txtb_FolderOut.Text).CreateSubdirectory(path);
                            File.AppendAllText(this.txtb_FolderOut.Text + @"\" + path + @"\" + info2.Name, contents);
                        }
                    }
                }
                MessageBox.Show("成功!");
            }
            else
            {
                DirectoryInfo info4 = new DirectoryInfo(this.txtb_FolderIn.Text);
                foreach (FileInfo info5 in info4.GetFiles("*.txt"))
                {
                    using (StreamReader reader2 = info5.OpenText())
                    {
                        string str5;
                        int num10;
                        int num11;
                        int num12;
                        Random random2;
                        int num8 = 0;
                        int num9 = 0;
                        bool flag2 = false;
                        if (this.txtb_Keywords.Text == string.Empty)
                        {
                            MessageBox.Show("输入不完全, 请填写完整!");
                        }
                        else
                        {
                            str5 = reader2.ReadToEnd();
                            num10 = str5.Length;
                            num11 = 0;
                            num12 = this.txtb_Keywords.Lines.Length;
                            if (num12 > this.txtb_Keywords.Lines.Length)
                            {
                                MessageBox.Show("插入个数不能小于插入内容栏内项的个数, 请重新输入!");
                            }
                            else
                            {
                                random2 = new Random(DateTime.Now.Second);
                                for (int k = 0; k < str5.Length; k++)
                                {
                                    if (str5[k] == ' ')
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (!flag2)
                                {
                                    MessageBox.Show("文章内无空格, 非法");
                                }
                                else
                                {
                                    if (!this.rb_PartIn.Checked)
                                    {
                                        goto Label_09F5;
                                    }
                                    num12 = int.Parse(this.txtb_RandomTime.Text);
                                    if (num12 <= this.txtb_Keywords.Lines.Length)
                                    {
                                        goto Label_08C7;
                                    }
                                    MessageBox.Show("插入个数不能小于插入内容栏内项的个数, 请重新输入!");
                                }
                            }
                        }
                        return;
                    Label_0747:
                        num8 = random2.Next(3, num10 - 2);
                        if ((str5[num8 - 1] == ' ') && (str5[num8] == ' '))
                        {
                            num9++;
                            num11 = random2.Next(num12 + 1, num12 + 100);
                            str5 = str5.Substring(0, num8) + spin.Spinner(this.txtb_Keywords.Lines[num11 % this.txtb_Keywords.Lines.Length], num11) + str5.Substring(num8);
                        }
                        else if (str5[num8 - 1] == ' ')
                        {
                            if (str5[num8 - 3] != '<')
                            {
                                num9++;
                                num11 = random2.Next(num12 + 1, num12 + 100);
                                str5 = str5.Substring(0, num8) + spin.Spinner(this.txtb_Keywords.Lines[num11 % this.txtb_Keywords.Lines.Length], num11) + " " + str5.Substring(num8);
                            }
                        }
                        else if ((str5[num8 + 1] == ' ') && (str5[num8 - 1] != '<'))
                        {
                            num9++;
                            num11 = random2.Next(num12 + 1, num12 + 100);
                            str5 = str5.Substring(0, num8 + 1) + " " + spin.Spinner(this.txtb_Keywords.Lines[num11 % this.txtb_Keywords.Lines.Length], num11) + str5.Substring(num8 + 1);
                        }
                    Label_08C7:
                        if (num9 < num12)
                        {
                            goto Label_0747;
                        }
                        goto Label_0A09;
                    Label_08D5:
                        num8 = random2.Next(3, num10 - 2);
                        if ((str5[num8 - 1] == ' ') && (str5[num8] == ' '))
                        {
                            str5 = str5.Substring(0, num8) + spin.Spinner(this.txtb_Keywords.Lines[num9], num8) + str5.Substring(num8);
                            num9++;
                        }
                        else if (str5[num8 - 1] == ' ')
                        {
                            if (str5[num8 - 3] != '<')
                            {
                                str5 = str5.Substring(0, num8) + spin.Spinner(this.txtb_Keywords.Lines[num9], num8) + " " + str5.Substring(num8);
                                num9++;
                            }
                        }
                        else if ((str5[num8 + 1] == ' ') && (str5[num8 - 1] != '<'))
                        {
                            str5 = str5.Substring(0, num8 + 1) + " " + spin.Spinner(this.txtb_Keywords.Lines[num9], num8) + str5.Substring(num8 + 1);
                            num9++;
                        }
                    Label_09F5:
                        if (num9 < this.txtb_Keywords.Lines.Length)
                        {
                            goto Label_08D5;
                        }
                    Label_0A09:
                        contents = str5;
                        File.AppendAllText(this.txtb_FolderOut.Text + @"\" + info5.Name, contents);
                    }
                }
                MessageBox.Show("成功!");
            }
        }
    }
    
     
    

      

  • 相关阅读:
    解决Volley请求网络数据返回的数据乱码
    AndroidStudio导入Android-PullToRefresh
    JavaScript判断文件的大小
    JavaScript POST 请求如何跨域
    使用Nginx在自己的电脑上实现负载均衡
    把列表中某一个属性的所有的值,按照一个符号给他弄成一个字符串
    Mongo中的数据类型
    Redis学习二 C#中如何进行这五种数据类型的操作
    Redis学习一 五种基本的数据类型
    JavaScript中关于bool类型判断的一些总结。
  • 原文地址:https://www.cnblogs.com/xssxss/p/2705496.html
Copyright © 2011-2022 走看看