byte[] ASCIIValues = Encoding.ASCII.GetBytes(myInput);
while (I < ASCIIValues.Length)
{
{
if ((ASCIIValues[I] > 65 & ASCIIValues[I] < 90) || (ASCIIValues[I] > 97 & ASCIIValues[I] < 122))
{
}
ASCIIValues[I] = 32;
}
Console.WriteLine(ASCIIValues[I]);
I++;
}
This is what I have now and I am trying to make sure the string the user enters (my Input) is within the ranges of being a letter only. I am trying to remove all punctuation and special characters as well as numbers. I is equal to 0 and is used to iterate through the array. Changing all unwanted characters to a space is because further down in my code I am removing the spaces anyway.
When running the code every returned ASCII value is 32. This makes no sense as letters should return the corresponding ASCII value.
(As L.B says, there are simpler ways of doing this – but it’s worth examining why your current code doesn’t work, too.)
Yes, it would do. Look closely at your loop:
You’re doing nothing within the
ifblock, and instead you’re unconditionally settingASCIIValues[I]to 32.Additionally:
forloop rather than awhileloop.'A'etc) would make the code simpler to read&&instead of&here