Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct DictPair {
- public string from;
- public string to;
- public int fromLen;
- public int toLen;
- public DictPair(string from, string to) {
- this.from = from;
- this.to = to;
- fromLen = from.Length;
- toLen = to.Length;
- }
- }
- private void ReplaceWord(RichTextBox rtb, DictPair w) {
- var src = w.@from;
- var dest = w.to;
- var srcLen = w.fromLen;
- var destLen = w.toLen;
- var start = 0;
- var index = rtb.Find(src, start, rtb.Rtf.Length, RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
- while (index >= 0) {
- rtb.Select(index, srcLen);
- rtb.SelectedText = dest;
- rtb.Select(index, destLen);
- tStruct.AddArea(new TextArea(index, destLen), srcLen);
- //rtb.SelectionColor = Color.Green;
- start += index + destLen;
- if (start < rtb.Text.Length)
- index = rtb.Find(src, start, rtb.Rtf.Length, RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
- else
- index = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement