private void DeleteDirtyWordsBase_Click(object sender, EventArgs e) { string extension = Application.StartupPath; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); //int line = MaintextBox.GetLineFromCharIndex(index) + 1;//得到当前行的行号,从0开始,习惯是从1开始,所以+1. string DeleteWordsStr = null; try { StreamReader sr = new StreamReader(extension + "\\品牌词库.txt", Encoding.GetEncoding("gb2312")); DeleteWordsStr = sr.ReadToEnd(); sr.Close(); } catch (Exception ex)//没有读取到文件 { MessageBox.Show("没有找到品牌词库文件!请先在可执行文件路径下导入【品牌词库.txt】 文件!" + ex); } if (DeleteWordsStr != null && DeleteWordsStr != "") { StringSearch iwords = new StringSearch(); iwords.SetKeywords(DeleteWordsStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); for (int i = 0; i < TitleStrList.Count(); i++) { string DeletedStr = iwords.Replace(TitleStrList[i], ' '); TitleStrList[i] = DeletedStr.Replace(" ", ""); } MaintextBox.Text = FormatStr(TitleStrList); MessageBox.Show("删除完成!"); } MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); }
private void OneKeyClearEnWords_Click(object sender, EventArgs e)//清除标题的字母 { string InsertStr = MaintextBox.Text; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); string strRemoved = Regex.Replace(InsertStr, "[a - b]", "", RegexOptions.IgnoreCase); strRemoved = Regex.Replace(strRemoved, "[d-l]", "", RegexOptions.IgnoreCase); strRemoved = Regex.Replace(strRemoved, "[n-z]", "", RegexOptions.IgnoreCase); strRemoved = Regex.Replace(InsertStr, "[A - B]", "", RegexOptions.IgnoreCase); strRemoved = Regex.Replace(strRemoved, "[D-L]", "", RegexOptions.IgnoreCase); InsertStr = Regex.Replace(strRemoved, "[N-Z]", "", RegexOptions.IgnoreCase); WordsSearch iwords = new WordsSearch(); string keywords = "c|C"; iwords.SetKeywords(keywords.Split('|')); List <WordsSearchResult> LocationresultList = iwords.FindAll(InsertStr); for (int i = 0; i < LocationresultList.Count(); i++) { int n = LocationresultList[i].Start; if (!(InsertStr.Substring(n + 1, 1) == "m" || InsertStr.Substring(n + 1, 1) == "M")) { InsertStr = InsertStr.Remove(n, 1); InsertStr = InsertStr.Insert(n, "*"); } } InsertStr.Replace("*", ""); MaintextBox.Text = InsertStr; MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); }
private void OneKeyReplace_Click(object sender, EventArgs e) { StringSearch iwords = new StringSearch(); string ChangeText = ChangeWordBox.Text; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); string ReplacedText = ReplaceBox.Text; if (ChangeText != "") { for (int i = 0; i < TitleStrList.Count(); i++) { string basestr = TitleStrList[i]; TitleStrList[i] = basestr.Replace(ChangeText, ReplacedText); } MaintextBox.Text = FormatStr(TitleStrList);//显示到textbox string extension = System.Windows.Forms.Application.StartupPath; //把关键字写入历史纪录 try { StreamReader sr = new StreamReader(extension + "\\HisToryReplaceword.txt", Encoding.GetEncoding("gb2312")); string KeyWordsStr = sr.ReadToEnd(); sr.Close(); using (FileStream fs = new FileStream(extension + "\\HisToryReplaceword.txt", FileMode.Open)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("gb2312"))) { sw.Write(ChangeText + "|"); sw.Write(KeyWordsStr); sw.Close(); } fs.Close(); } } catch //没有读取到文件 { using (FileStream fs = new FileStream(extension + "\\HisToryReplaceword.txt", FileMode.Create)) //新建一个文件 { using (StreamWriter newFile = new StreamWriter(fs, Encoding.GetEncoding("gb2312"))) { newFile.Write(ChangeText + "|"); newFile.Close(); } fs.Close(); } } } else { } MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); }
private void DeleteMoreThen30_Click(object sender, EventArgs e) { int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); //int line = MaintextBox.GetLineFromCharIndex(index) + 1;//得到当前行的行号,从0开始,习惯是从1开始,所以+1. deletemorethan30(); MaintextBox.Text = FormatStr(TitleStrList); //MaintextBox.Select(index, 0); MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret(); MaintextBox.Focus(); }
private void OneKeyClearNum_Click(object sender, EventArgs e)//清除标题中的数字 { string InsertStr = MaintextBox.Text; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); string ChangedStr = Regex.Replace(InsertStr, @"\d", ""); //StringSearch iwords = new StringSearch(); //string keywords = "0|1|2|3|4|5|6|7|8|9"; //iwords.SetKeywords(keywords.Split('|')); //string ChangedStr = iwords.Replace(InsertStr, ' '); //ChangedStr = ChangedStr.Replace("\r\n", ""); MaintextBox.Text = ChangedStr; MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); //SaveChange(ChangedStr); }
private void OneKeyClearPunctuation_Click(object sender, EventArgs e) { string InsertStr = MaintextBox.Text; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); StringSearch iwords = new StringSearch(); //string keywords = "!|@|#|$|%|^|&|*|(|)|、|“|”|+|……|!|#|¥|(|)| |【|】|[|]|{|}|/|.|。|~|~"; string[] keyword = { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "、", "“", "”", "+", "……", "!", "#", ":", "¥", "(", ")", "【", "】", "[", "]", "{", "}", "/", "\\+", ".", "。", "~", "~", "|", "\"" }; iwords.SetKeywords(keyword); string ChangedStr = iwords.Replace(InsertStr, ' '); //ChangedStr = ChangedStr.Replace("\r\n", ""); ChangedStr = ChangedStr.Replace(" ", ""); MaintextBox.Text = ChangedStr;//改变txtbox内容 MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); //SaveChange(ChangedStr); }
private void OneKeyAddKeyWords_Click(object sender, EventArgs e) { AddWayForm adddwayform = new AddWayForm(); // this.Visible = false; int index = MaintextBox.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引 int line = GetTextboxLine(index); //int line = MaintextBox.GetLineFromCharIndex(index) + 1;//得到当前行的行号,从0开始,习惯是从1开始,所以+1. adddwayform.ShowDialog(this); string keyword_1 = KeyWordsOne.Text; string keyword_2 = KeyWordsTwo.Text; string keyword_3 = KeyWordThree.Text; int addway = 1;//默认从前添加 if (AddType != 0) { if (checkBox3.Checked)//从后添加 { addway = 3; } if (radioButton1.Checked)//如果大于三十就删除最后几个 { addway = addway * 3; } else if (radioButton2.Checked)//如果大于三十就不添加(要先判断)【如果原标题28字符以上就一个都不加】 { addway = addway * 5; }//3(前,删除最后几个),5(前,大于三十不添加),9(后,删除最后几个),15(后,大于三十不添加) GetAddstr(addway, keyword_1, keyword_2, keyword_3); AddType = 0;//重置值 MaintextBox.Text = FormatStr(TitleStrList);//显示到textbox MaintextBox.SelectionStart = getnewindex(line); MaintextBox.SelectionLength = 0; MaintextBox.ScrollToCaret();//到指定行 MaintextBox.Focus(); } else { } }