I am trying to input a string into a C# console app, have it break the string into an array of its characters, and then have it iterate through the array of characters and assign each character an integer corresponding to its alphabetic position(1-26, a-z) and populate a new array with the integers.
The input block up to the array of characters I already have:
string plainText;
Console.Write ("String:");
plainText = Console.ReadLine();
char[] plainTextArray = plainText.ToCharArray();
Not looking for a completed solution, more of a suggested direction to look in for a function(s) to implement.
Thanks.
Two possible solutions here:
charto anint, subtract an appropriate amount to put it between 1-52, and take the number mod 26 (or .ToUpper() or ToLower() the string beforehand and put it in the 1-26 range)Dictionary<char, int>that takes acharand returns the appropriate numberI recommend the first option.
EDIT:
Based on phoog’s comment, I recommend the following method:
String.ToUpper()to convert the string to uppercase.String.ToCharArray()to create the array of uppercase characters.int[]array that is the same size as thechar[]array.