title: c# switch all letters in a string for a different pre-chosen letter
body: <p>Whilst working on a simple project I was trying to come up with a very basic cryptographic system which will allow me to switch letters in a message to another pre-chosen letter. So far I have tried a few ways but have so far been unsuccessful in my attempts. (*NOTE: This is not for anything other then learning the basics of c# so randomness and security is not important in this case, I simply want to turn one letter into another for the sake of learning how to do it) </p>
  
  <p>so first I started by defining some strings such as this </p>
  
  <pre><code>string a = "a";
  string b = "b";
  string c = "d";
  ..... //continues to string z = "z"
  </code></pre>
  
  <p>next I tried to create a new string based on the values that have been input in to a textbox called <code>PlainTextBox</code> and place them inside a separate textbox called <code>ChangedTextBox</code>. this code is triggered with a button click event. </p>
  
  <pre><code>string str = PlainTextBox.Text;
  char[] array = str.ToCharArray();
  array[int.Parse(a)] = 'x';
  array[int.Parse(b)] = 'y';
  array[int.Parse(c)] = 'z';
  .......// continues to (z)
  str = new string(array);
  ChangedTextBox.Text = str;
  </code></pre>
  
  <p>but this code throws an exception because the input is not a valid integer. the basic Idea is that if the user types "abc" in the <code>PlainTextBox</code> and pushes a button, the <code>ChangedTextBox</code> should show "xyz" but should be inclusive of the whole text in PlainTextBox, switching every letter in the message to its chosen counterpart. </p>
  
  <p>Besides the error I receive, this code seems very cumbersome and inefficient. </p>
  
  <p>Is there a faster way to achieve this result?  </p>