title: Trying to replace letters in a string with the corresponding letter in the alphabet with a similar frequency
body: <p>As the title states I am trying to replace letters in a specific string with the highest frequency with the corresponding letter in the alphabet.</p>
  
  <p>For example, if the string has the most <code>D</code>s in it then i would replace all the <code>D</code>s with an <code>E</code> as that is the most common letter in the alphabet, i would then continue this process going down the letter frequencies...</p>
  
  <p>So i have had a shot but my output is completely wrong.</p>
  
  <p>Im completely new to progroqamming so im sorry if it all disgusts you, but id still like to do it in the format i have already been following.</p>
  
  <p>I have linked my code as follows, i have done it in a few separate methods, i was wondering if anyone can spot the problem i am having.</p>
  
  <p>I believe it is replacing the wrong letter but i really have no idea, i have only done a simple ceasar cipher before so this isnt a large step but i really cant get my head round whats going wrong.</p>
  
  <p>Oh and please ignore variable names etc they are just place holders:</p>
  
  <pre><code>public class Decode
  {
      public static void doDecode()
      {
          string decoding = File.ReadAllText(@"thing.txt", Encoding.Default);
          string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          int counter = 0;
          int amount = 0;
          int[] letterAmounts = new int[26];
  
          decoding = decoding.Replace(Environment.NewLine, "");
          decoding = decoding.Replace(" ", "");
  
          foreach (char k in alphabet)
          {
              amount = Advanced.Adv(decoding, k);
              letterAmounts[counter] = amount;
              counter++;
          }
          File.WriteAllText(@"stuff.txt", Change.doChange(decoding, letterAmounts));
          System.Diagnostics.Process.Start(@"stuff.txt");
      }
  }
  </code></pre>
  
  <p>So this simply calls the other classes and assigns the numbers found to an array</p>
  
  <pre><code>public class Advanced
  {
      public static int Adv(string test, char c)
      {
          int count = 0;
          foreach (char x in test)
          {
              if (x == c)
              {
                  count = count + 1;
              }
          }
  
          return count;
      }
  }
  </code></pre>
  
  <p>This is called previously and simply counts the amount there is of a letter</p>
  
  <pre><code>public class Change
  {
      public static string doChange(string test, int[] letterAmounts)
      {
          string frequency = "ETAOINSHRDLCUMWFGYPBVKJXQZ";
          char[] mostFrequent = frequency.ToCharArray();
          string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          char[] abc = alphabet.ToCharArray();
          int most = 0;
          int position = 0;
          for (int tester = 0; tester &lt; 26; tester++)
          {
              most = letterAmounts.Max();
              position = Array.IndexOf(letterAmounts, most);
              test = test.Replace(abc[position], mostFrequent[tester]);
              letterAmounts[position] = 0;
          }
          return test;
      }
  }
  </code></pre>
  
  <p>This is where i believe the problems lay but i cannot get my head around why, again i know its messy but any help is deeply appreciated.</p>