title: Increment a value from AAA to ZZZ with cyclic rotation
body: <p>I need to code a method that increment a string value from AAA to ZZZ with cyclic rotation (next value after ZZZ is AAA)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public static string IncrementValue(string value) {
          if (string.IsNullOrEmpty(value) || value.Length != 3) {
              string msg = string.Format("Incorrect value ('{0}' is not between AAA and ZZZ)", value);
              throw new ApplicationException(msg);
          }
          if (value == "ZZZ") {
              return "AAA";
          }
          char pos1 = value[0];
          char pos2 = value[1];
          char pos3 = value[2];
  
          bool incrementPos2 = false;
          bool incrementPos1 = false;
  
          if (pos3 == 'Z') {
              pos3 = 'A';
              incrementPos2 = true;
          } else {
              pos3++;
          }
  
          if (incrementPos2 &amp;&amp; pos2 == 'Z') {
              pos2 = 'A';
              incrementPos1 = true;
          } else {
              if (incrementPos2) {
                  if (pos2 == 'Z') {
                      pos2 = 'A';
                      incrementPos1 = true;
                  }
                  pos2++;
              }
          }
  
          if (incrementPos1) {
              pos1++;
          }
  
          return pos1.ToString() + pos2.ToString() + pos3.ToString();
      }
  </code></pre>
  
  <p>I know this piece of code is quite dirty and not very efficient but I dont know how to do it properly.</p>
  
  <p>How is secured this snippet?
  (this will only run on windows plaform)</p>
  
  <p>How can I optimize-it and make it more readable ?</p>
  
  <p>Thanks for your comments</p>