I'm trying to create a method that subs letters from a shuffled alphabet into the letters of an input but I keep getting IndexOutOfRange and don't know why.
In the debugger it says letterIndex equals -1 but I don't know how.
private string SubCypher(string input, string charsToSub)
{
char[] charsToSubArr = charsToSub.ToCharArray();
char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
char[] inputChars = input.ToCharArray();
for(int index = 0; index < inputChars.Length; index++)
{
char toBeSubbed = inputChars[index];
int letterIndex = Array.IndexOf(alphabet, toBeSubbed);
inputChars[index] = charsToSubArr[letterIndex];
}
return new string(inputChars);
}
private void transformButton_Click(object sender, EventArgs e)
{
string input = inputTextBox.Text;
switchCaseTextBox.Text = SwitchCase(input);
reverseTextBox.Text = Reverse(input);
pigLatinTextBox.Text = PigLatin(input);
shiftTextBox.Text = ShiftCypher(input, 3);
subTextBox.Text = SubCypher(input, "NBAJYFOWLZMPXIKUVCDEGRQSTH");
}