c# - Increment a value from AAA to ZZZ with cyclic rotation -


itemprop = "text">

I need a method code which is to increase a string value from AAA to ZZZ with rotational rotation (ZZZ after the next value This is my code:

  public static string increase value (string value) {if (string.IsNullOrEmptE (value) || value.Length! = 3) {string Msg = string.Format ("wrong 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]; Bull growth Pos2 = false; Bull growth Pos1 = false; If (pause3 == 'z') {pos3 = 'A'; Salary increase Pos2 = true; } Else {pos3 ++; } If (increment Pos2 & pos2 == 'Z') {pos2 = 'A'; Increment Pos1 = true; } And (if increment Pos2) {if (pos2 == 'Z') {pos2 = 'A'; increment Pos1 = true;} Pos2 ++;}} If (increment Pos1) {pos1 ++; } Return Pause 1. Toastring () + Pause 2. Toastring () + Pause 3. Toastring ();}  

I know this piece of code is very dirty and very efficient But I do not know how to do it properly.

How safe is this snippet? << P>

How can I optimize it and more Can I Make Readable?

Thanks for the comments

Think mathematically about this: your strings (AAA, AAB, ...) Only natural numbers (000, 001, ...) behave like the exception of having base 26 instead of base 10.

Therefore, you can use the same principle here is some code: 0 to 26 ^ 3 - 1 intinchargement value (int i) {// a written "return (i + 1)% 26% ^ 3" i + +; If (i == 26 * 26 * 26) I = 0; return i;} // convert 0a AA, 1 to AAB, ... string format value (int i) {var result = new stringbiller (); result. Identity (0, (four) ('a' + (i% 26); I / = 26; results. Identification (0, (four) ('a' + (i% 26)); I / = 26; Results (0, (four) ('a' + (i% 26)) return result. Toaster ();}


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -