コード例 #1
0
        private void btnSaveByContainAnyStr_Click(object sender, EventArgs e)
        {
            //某行带这些内容则保留,以 | 符号组合

            saveBeforeContent();
            //获取每行内容组成的List
            List <string> list = richInput.Text.Split('\n').ToList();
            List <string> listNeedExistedString = txtOperContent.Text.Split('|').ToList();

            richInput.Text = "";
            StringBuilder sb = new StringBuilder();

            foreach (string line in list)
            {
                bool isExisted = false;
                foreach (string str in listNeedExistedString)
                {
                    if (line.ToLower().Contains(str.ToLower()))
                    {
                        isExisted = true;
                        break;
                    }
                }
                if (isExisted)
                {
                    sb.AppendFormat(line + "\n");
                }
            }
            richInput.Text = sb.ToString();

            TransferHelper.ExecuteInsert("SaveByContainAnyStr", $"{txtOperContent.Text}");
        }
コード例 #2
0
        private void btnRemoveEveryRowSuffixStrExeceptEmptyRow_Click(object sender, EventArgs e)
        {
            //移除每行后 字符串

            //txtAppendToEnd.Text = txtAppendToEnd.Text.Trim();

            StringBuilder sb = new StringBuilder();

            foreach (string line in richInput.Text.GetSplitLineKeepEmptyRow())
            {
                int index = line.LastIndexOf(txtAppendToEnd.Text);

                if (index >= 0)
                {
                    if (chkContainThatSuffixStr.Checked)
                    {
                        sb.Append(line.Substring(0, index) + "\n");
                    }
                    if (!chkContainThatSuffixStr.Checked)
                    {
                        sb.Append(line.Substring(0, index + txtAppendToEnd.Text.Length) + "\n");
                    }
                }
                else
                {
                    sb.Append(line + "\n");
                }
            }
            richInput.Text = sb.ToString().RemoveLastChar();

            TransferHelper.ExecuteInsert("RemoveEveryRowSuffixStrExeceptEmptyRow", txtAppendToEnd.Text);
        }
コード例 #3
0
        private void btnReplaceToTab_Click(object sender, EventArgs e)
        {
            saveBeforeContent();
            //将内容替换为制表符
            richInput.Text = richInput.Text.Replace(txtOriginStr.Text, "\t");

            //如果新的地方提示没有这数据库,记得在Form1那里初始化数据库
            TransferHelper.ExecuteInsert("ReplaceToTab", txtReplaced.Text);
        }
コード例 #4
0
        private void btnSixSpaceToBreakLine_Click(object sender, EventArgs e)
        {
            saveBeforeContent();
            //将六个空格替换为换行
            //中文全角空格为\u3000,英文半角空格为\u0020,
            richInput.Text = (new Regex("[\u0020\u3000]{6}")).Replace(richInput.Text, "\n");

            //如果新的地方提示没有这数据库,记得在Form1那里初始化数据库
            TransferHelper.ExecuteInsert("SixSpaceToBreakLine");
        }
コード例 #5
0
 public static void InsertDatabase(ReplaceHistoryModel replaceHistoryModel)
 {
     try
     {
         TransferHelper.ExecuteInsert(replaceHistoryModel);
     }
     catch (ExceptionEx ex)
     {
         MessageBox.Show(ex.MessageEx);
     }
 }
コード例 #6
0
        private void btnStringToBreakLine_Click(object sender, EventArgs e)
        {
            saveBeforeContent();

            StringBuilder sb = new StringBuilder();

            foreach (string str in richInput.Text.GetSplitLineKeepEmptyRow())
            {
                sb.Append(replaceToSpalce(ReplaceStr(str, txtOriginStr.Text, "      ")));
            }
            richInput.Text = sb.ToString();

            //如果新的地方提示没有这数据库,记得在Form1那里初始化数据库
            TransferHelper.ExecuteInsert("SixSpaceToBreakLine");
        }
コード例 #7
0
        private void btnAddBeforeExceptEmptyR_Click(object sender, EventArgs e)
        {
            //在每行前新增txtAppend.Text

            //txtAppendToBefore.Text = txtAppendToBefore.Text.Trim();
            //获取每行内容组成的List
            StringBuilder sbOutput = new StringBuilder();

            foreach (string str in richInput.Text.GetSplitLineKeepEmptyRow())
            {
                if (string.IsNullOrEmpty(str))
                {
                    sbOutput.AppendLine();
                    continue;
                }
                sbOutput.AppendLine(txtAppendToBefore.Text + str);
            }
            richInput.Text = sbOutput.ToString().RemoveLastChar();

            TransferHelper.ExecuteInsert("AddBeforeExceptEmpty", txtAppendToBefore.Text);
        }
コード例 #8
0
        private void btnAddEverRowSuffixStrExceptEmptyRow_Click(object sender, EventArgs e)
        {
            //新增到每行最尾端

            //txtAppendToEnd.Text = txtAppendToEnd.Text.Trim();
            //获取每行内容组成的List
            List <string> list = StringUtils.GetSplitLine(richInput.Text);
            StringBuilder sb   = new StringBuilder();

            foreach (string line in list)
            {
                if (string.IsNullOrEmpty(line.Trim()))
                {
                    sb.Append(line + "\n");
                    continue;
                }
                sb.AppendLine(line + txtAppendToEnd.Text.ToString().Trim());
            }
            richInput.Text = sb.ToString().RemoveLastChar();

            TransferHelper.ExecuteInsert("AddEverRowSuffixStrExceptEmptyRow", txtAppendToEnd.Text);
        }
コード例 #9
0
        /// <summary>
        /// 某行不带这些内容则保留,以|符号组合
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveByNotContainAnyStr_Click(object sender, EventArgs e)
        {
            //获取每行内容组成的List
            List <string> list = richInput.Text.Split('\n').ToList();
            List <string> listNeedExistedString = txtOperNotContained.Text.Split('|').ToList();

            int           lineIndex             = 0;
            List <int>    listNeedRemoveIndexS1 = new List <int>();        //带有这些内容,则这行不保留,需要从list中移除
            StringBuilder sb = new StringBuilder();

            foreach (string line in list)
            {
                bool isExisted = false;
                foreach (string str in listNeedExistedString)
                {
                    if (line.ToEncryInneredParticularWord().Contains(str.ToEncryInneredParticularWord()))
                    {
                        isExisted = true;
                        break;
                    }
                }
                if (isExisted)
                {                   //如果带了这些内容,就不存这行了
                    listNeedRemoveIndexS1.Add(lineIndex);
                }
                lineIndex++;
            }

            //使用对比插入
            List <int> listNeedRemoveIndexS2 = new List <int>();           //带有这些内容,则这行不保留,需要从list中移除
            int        s1TotalCount          = listNeedRemoveIndexS1.Count();

            for (int i = 0; i < s1TotalCount; i++)
            {
                int operIndex = listNeedRemoveIndexS1[i];
                listNeedRemoveIndexS2.Add(operIndex);

                int beforeRowNum = txtConcludeBeforeRowNum.Text.ToInt32();
                if (beforeRowNum > 0)
                {
                    int temp = 1;
                    while (operIndex >= temp && temp <= beforeRowNum)
                    {
                        listNeedRemoveIndexS2.Add(operIndex - temp);
                        temp++;
                    }
                }

                int afterRowNum = txtConcludeAfterRowNum.Text.ToInt32();
                if (afterRowNum > 0)
                {
                    int temp = 1;
                    while (operIndex + temp < list.Count && temp <= afterRowNum)
                    {
                        listNeedRemoveIndexS2.Add(operIndex + temp);
                        temp++;
                    }
                }
            }

            listNeedRemoveIndexS2 = listNeedRemoveIndexS2.Distinct().ToList();
            listNeedRemoveIndexS2.SortByDesc <int>();

            foreach (int removeIndex in listNeedRemoveIndexS2)
            {
                list.RemoveAt(removeIndex);
            }

            foreach (var saveRow in list)
            {
                sb.Append($"{saveRow}\n");
            }
            richInput.Text = sb.ToString().RemoveLastChar();

            TransferHelper.ExecuteInsert("SaveByNotContainAnyStr", $"{txtOperNotContained.Text}");
        }