I have a homework assignment where the program will accept any phone number in the format similar to 555-GET-FOOD. The task is to map the alphabetic letters to numbers and tran
While "map" (implemented as Dictionary
in C#/.Net) is probably best choice for this problem, basic math is enough for such simple transformation:
Console.WriteLine(String.Join("", // combine characters back to string
"555-GET-FOOD" //value
.ToUpperInvariant() // carefully converting to avoid Turkish I problems
.Select(c=> (c>='A' && c<='Z') ? // only tweak A-Z range
Math.Min((c-'A')/3+2,9).ToString()[0] : c)))