The c# program I'm developing checks the first character of user input and if it starts with . (dot) I want to replace each character of user input with pacified character string while the user is writing, but I'm getting the error
Index out of bounds exception
My code:
if (textBox1.Text.StartWith(".")) {
string MyText = "Hello World";
int x = 0;
string NewText;
while (x <= MyText.Length) {
NewText = textBox1.Text.Replace(textBox1.Text[x], MyText[x]);
TextBox1.Text = NewText;
x++;
}
}
x<=MyText.Lengthgoes out of bounds. Arrays are 0 indexed.