This was a portion of a skills test given to me by a company. The task was to write a method that takes a string, reverses it, and sets the vowels as capitals and consonants to lowercase. I was also told to prove that my implementation works.
using System;
using System.Diagnostics;
namespace StringOperation
{
using static Console;
internal class Program
{
#region Entry
private static void Main()
{
while (true)
{
WriteLine(MessageStrings.REQUEST_NAME);
var strResult = ReadLine();
var result = ProcessInput(string.IsNullOrEmpty(strResult) ? MessageStrings.PROOF : strResult );
if ((ReadKey(true).Key ^ ConsoleKey.Y) == 0)
continue;
break;
}
}
#endregion
#region Logic
private static string ProcessInput(string input)
{
var output = new char[input.Length];
var desc = output.Length;
var asnd = -1;
while(asnd++ <= desc--)
{
// unroll and reverse
output[asnd] = Shift(input[desc]);
output[desc] = Shift(input[asnd]);
}
return new string(output);
}
private static char Shift(char target)
{
// switching the 32 bit and returning the new value
var i = (target | 0x20);
// Checking if a the new value is a symbol
if (i < 97 || i > 122)
return target;
switch (i)
{
case 97:
case 101:
case 105:
case 111:
case 117:
// Returning a capital vowel
return (char) (target & ~0x20);
default:
// returning Lower case consonant
return (char) (i);
}
}
#endregion
}
}