private void ReplaceButton_Click(object sender, EventArgs e) { if (Find_TextBox.Text.Length <= 0) { MessageBox.Show("You didn't enter anything to search for. Please Try Again"); } if (Replace_TextBox.Text.Length <= 0) { MessageBox.Show("You didn't enter anything to replace with. Please Try Again"); } if (findNextPhrase) { MessageBox.Show("You need to find something before you can try replacing it..."); } else if (findNextPhrase == false) { Editor_TextBox.Text = Editor_TextBox.Text.Remove(startPosition - endPosition, Find_TextBox.Text.Length); Editor_TextBox.Text = Editor_TextBox.Text.Insert(startPosition - endPosition, Replace_TextBox.Text); endPosition = this.Replace_TextBox.Text.Length; startPosition = startPosition + endPosition; endEditor = Editor_TextBox.Text.Length; startPosition = Editor_TextBox.SelectionStart + 1; if (previousSearchPhrase != Find_TextBox.Text) { endPosition = 0; numPhraseFound = 0; } for (int i = 0; i < endEditor; i = startPosition) { previousSearchPhrase = this.Find_TextBox.Text; isCurrentlySearching = true; if (i == -1) { isCurrentlySearching = false; break; } startPosition = Editor_TextBox.Find(Find_TextBox.Text, startPosition, endEditor, RichTextBoxFinds.None); if (startPosition >= 0) { numPhraseFound++; //Editor_TextBox.SelectionColor = Color.Blue; //saving this value for later use endPosition = this.Find_TextBox.Text.Length; startPosition = startPosition + endPosition; break; } } } }
private void FindText() { if (Find_TextBox.Text.Length <= 0) { MessageBox.Show("You didn't enter anything to search for. Please Try Again"); } else { findNextPhrase = true; endEditor = Editor_TextBox.Text.Length; startPosition = Editor_TextBox.SelectionStart + 1; if (previousSearchPhrase != Find_TextBox.Text) { endPosition = 0; numPhraseFound = 0; } for (int i = 0; i < endEditor; i = startPosition) { previousSearchPhrase = this.Find_TextBox.Text; isCurrentlySearching = true; if (i == -1) { isCurrentlySearching = false; break; } if (startPosition >= endEditor) { MessageBox.Show("Reached the end of the file"); break; } startPosition = Editor_TextBox.Find(Find_TextBox.Text, startPosition, endEditor, RichTextBoxFinds.None); if (startPosition >= 0) { findNextPhrase = false; numPhraseFound++; //Editor_TextBox.SelectionColor = Color.Blue; //saving this value for later use endPosition = this.Find_TextBox.Text.Length; startPosition = startPosition + endPosition; break; } if (numPhraseFound == 0) { MessageBox.Show("No Match Found!!!"); } } } }
private void FindText() { endEditor = Editor_TextBox.Text.Length; startPosition = Editor_TextBox.SelectionStart + 1; if (previousSearchPhrase != Find_TB.Text) { startPosition = 0; endPosition = Find_TB.Text.Length; numPhrasesFound = 0; } for (int i = 0; i < endEditor; i = startPosition) { searchPhrase_selected = false; if (i == -1) { MessageBox.Show("Reached the end of the file"); break; } if (startPosition >= endEditor) { startPosition = 0; break; } startPosition = Editor_TextBox.Find(Find_TB.Text, startPosition, endEditor, RichTextBoxFinds.None); if (startPosition >= 0) { numPhrasesFound++; searchPhrase_selected = true; endPosition = this.Find_TB.Text.Length; startPosition = startPosition + endPosition; previousSearchPhrase = this.Find_TB.Text; break; } if (numPhrasesFound == 0) { MessageBox.Show("No Match Found!!!"); break; } } }
private void SearchForPairs() { int duplicate = -1; string searchDirection = ""; string searchText = ""; int index = Editor_TextBox.SelectionStart; char[] ch = Editor_TextBox.Text.ToCharArray(); char selectedText; int duplicatesFound = 0; endEditor = Editor_TextBox.Text.Length; startPosition = Editor_TextBox.SelectionStart; if (index - 1 < 0) { index = 0; } else if (index - 1 > Editor_TextBox.Text.Length) { index = Editor_TextBox.Text.Length; } selectedText = ch[index - 1]; switch (selectedText) { case '[': searchDirection = "down"; searchText = "]"; break; case ']': searchDirection = "up"; searchText = "["; break; case '{': searchDirection = "down"; searchText = "}"; break; case '}': searchDirection = "up"; searchText = "{"; break; case '(': searchDirection = "down"; searchText = ")"; break; case ')': searchDirection = "up"; searchText = "("; break; } for (int i = 0; i < endEditor + 1; i = startPosition) { duplicate = -1; if (startPosition >= endEditor + 1 || i == -1) { break; } else { if (searchDirection == "down") { startPosition = Editor_TextBox.Find(searchText, index, endEditor + 1, RichTextBoxFinds.None); if (startPosition >= 0) { //we found the character, lets make sure its the correct match to our pair duplicate = Editor_TextBox.Find(selectedText.ToString(), index, startPosition + 1, RichTextBoxFinds.NoHighlight); if (duplicate != -1) { duplicatesFound++; index = duplicate + 1; } else { if (duplicatesFound != 0) { index = startPosition + 1; duplicatesFound--; } else { break; } } } else { break; } } else { startPosition = Editor_TextBox.Find(searchText, 0, index, RichTextBoxFinds.Reverse); if (startPosition >= 0) { //we found the character, lets make sure its the match duplicate = Editor_TextBox.Find(selectedText.ToString(), startPosition, index - 1, RichTextBoxFinds.Reverse | RichTextBoxFinds.NoHighlight); if (duplicate != -1) { duplicatesFound++; index = duplicate - 1; } else { if (duplicatesFound != 0) { index = startPosition - 1; duplicatesFound--; } else { break; } } } else { break; } } } } }