public static FoundText Find(this string s, string f) { if (f.Length > s.Length) { return(null); } else { FoundText ft = new FoundText(); ft.StartIndex = s.IndexOf(f); ft.EndIndex = ft.StartIndex + f.Length - 1; return(ft); } }
public static List <FoundText> FindAll(this string s, string f) { if (f.Length > s.Length) { return(new List <FoundText>()); } else { List <FoundText> fArray = new List <FoundText>(); bool b = false; int newStartIndex = 0; if (s.IndexOf(f) >= 0) { b = true; FoundText ft = new FoundText(); ft.StartIndex = s.IndexOf(f); ft.EndIndex = ft.StartIndex + f.Length - 1; fArray.Add(ft); newStartIndex = ft.StartIndex + f.Length; } while (b) { dynamic f_new = s.Substring(newStartIndex); if (f_new.IndexOf(f) >= 0) { FoundText ft = new FoundText(); ft.StartIndex = f_new.IndexOf(f) + newStartIndex; ft.EndIndex = ft.StartIndex + f.Length - 1; fArray.Add(ft); newStartIndex = f_new.IndexOf(f) + f.Length + newStartIndex; } else { b = false; } } return(fArray); } }
public void FindNext() { var start = rbDown.Checked ? ++_last : --_last; var found = false; var found_text = ""; if (rbDown.Checked) { for (; _last < _text.Length; _last++) { if (!find(_text[_last], out found_text)) { continue; } found = true; break; } if (!found) { for (_last = 0; _last < start; _last++) { if (!find(_text[_last], out found_text)) { continue; } found = true; break; } } } else { for (; _last > 0; _last--) { if (!find(_text[_last], out found_text)) { continue; } found = true; break; } if (!found) { for (_last = _text.Length - 1; _last > start; _last--) { if (!find(_text[_last], out found_text)) { continue; } found = true; break; } } } if (!found) { MessageBox.Show(@"Text not found."); return; } if (!_found.ContainsKey(_last + 1)) { grdResults.Rows.Add(_last + 1, _text[_last], found_text); _found.Add(_last + 1, _found.Count); } grdResults.Rows[_found[_last + 1]].Selected = true; grdResults.CurrentCell = grdResults.Rows[_found[_last + 1]].Cells[0]; FoundText?.Invoke(this, new FoundTextEventHandlerArgs(txtSearch.Text, _last)); }
private void grdResults_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { FoundText?.Invoke(this, new FoundTextEventHandlerArgs(txtSearch.Text, Convert.ToInt32(grdResults.SelectedRows[0].Cells[0].Value) - 1)); }