Advertisement
KpoKec

Untitled

May 12th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1.         public struct DictPair {
  2.             public string from;
  3.             public string to;
  4.             public int    fromLen;
  5.             public int    toLen;
  6.  
  7.             public DictPair(string from, string to) {
  8.                 this.from = from;
  9.                 this.to   = to;
  10.                 fromLen   = from.Length;
  11.                 toLen     = to.Length;
  12.             }
  13.         }
  14.  
  15.         private void ReplaceWord(RichTextBox rtb, DictPair w) {
  16.             var src     = w.@from;
  17.             var dest    = w.to;
  18.             var srcLen  = w.fromLen;
  19.             var destLen = w.toLen;
  20.  
  21.             var start = 0;
  22.             var index = rtb.Find(src, start, rtb.Rtf.Length, RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
  23.             while (index >= 0) {
  24.                 rtb.Select(index, srcLen);
  25.                 rtb.SelectedText = dest;
  26.                 rtb.Select(index, destLen);
  27.                 tStruct.AddArea(new TextArea(index, destLen), srcLen);
  28.                 //rtb.SelectionColor =  Color.Green;
  29.                 start += index + destLen;
  30.                 if (start < rtb.Text.Length)
  31.                     index = rtb.Find(src, start, rtb.Rtf.Length, RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
  32.                 else
  33.                     index = -1;
  34.             }
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement