title: im trying to get the index of words in a textbox.Text and add it to textBox2 but its not working good
body: <p>This is the code :</p>
  
  <pre><code>private void BtnScrambleText_Click(object sender, EventArgs e)
          {
              textBox1.Enabled = false;
              BtnScrambleText.Enabled = false;
              StringBuilder sb = new StringBuilder();
              var words = textBox1.Text.Split(new char[] { ' ', '"', ',', '-', '&gt;', '\r', '\n', ':', '.', '&lt;', '/', '=', '\\' }, StringSplitOptions.RemoveEmptyEntries);
              int index = 0;
              int nextIndex = 0;
              for (int i = 0; i &lt; words.Length; i++)
              {
                  string word = words[i];
                  int wordWidth = word.Length;
                  index = textBox1.Text.IndexOf(word, index);
                  string t = textBox1.Text.Substring(nextIndex, index);
                  textBox2.AppendText(t);
                  string s = textBox1.Text.Substring(index, wordWidth);
                  if (index == -1) break;
  
                  if (word.Length &gt; 0)
                  {
                      ScrambleTextBoxText scrmbltb = new ScrambleTextBoxText(s.Trim());
                      scrmbltb.GetText();
                      sb.Append(word.Replace(s.Trim(), scrmbltb.scrambledWord));
                      textBox2.AppendText(sb.ToString());
                  }
  
              }
          }
  </code></pre>
  
  <p>I know there are other ways but i want to use indexof and substring.</p>
  
  <p>First im getting all the words from the textBox and add them to variable words.
  Then in the loop first im getting the content of textBox1 untill the first word and add it to textBox2.</p>
  
  <p>Then i find the first word index then substring so the variable s contain the word .
  Im scrambling the word then add the word to textBox2.
  The idea was :</p>
  
  <ol>
  <li>To add the content untill the first word .</li>
  <li><p>To add the scrambled word right after the first content.</p></li>
  <li><p>To add the next content from the last found word untill the next word.</p></li>
  <li>Add in the last position last index the next scrambled word.</li>
  </ol>
  
  <p>And so on so in the end the content in textBox2 wil be the same format as it is in textBox1 but the words in textBox2 will be scrambled.</p>
  
  <p>The problem is when i click the button its adding a lot of times the content and words to textBox2 and make a lot of mess.</p>
  
  <p>Why is that how can i fix it ?</p>
  
  <p>EDIT**</p>
  
  <p>When entering manual text to the textBox1 for example:</p>
  
  <pre><code>    ? where am i ? ! hello im here -----
       _______________
  </code></pre>
  
  <p>what is the time in few hi everyone ? : ></p>
  
  <p>I started to type in textBox1 after few spaces then added some chars like - ? > and more then i pressed the enter key and added the other line.</p>
  
  <p>The result in textBox2 is:</p>
  
  <p>wrhee     hlelo  hree -----
           <strong><em>_</em>__<em>_</em>___</strong></p>
  
  <p>waht   tmie    evoyrnee </p>
  
  <p>The words that i needed are scrambled good and in place the problem is that it didnt copy the signs ? and > and it didnt copy the rest of the content which wasnt scrambled. the words : is the few im hi wasnt copy to textBox2.</p>
  
  <p>I wanted that the whole content to copy to textBox2 with spaces and everything but only the words i need to be scrambled. </p>
  
  <p>The scramble part is working but the content copy is not.</p>