remove the next word in a string in C#?
I want to remove the next word from the text (next, after the position of the caret), but it returns an unhandled exception..any help? private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { int position = TextArea.SelectionStart; //get position of caret int MaxLength = TextArea.Text.Length; //get textbox's text length String ForwardString = TextArea.Text.Substring(position, MaxLength); //filter from caret to the end of the text bool MetChar = false; // when you meet a character that is not whitespace you get allowed to break when you meet a whitespace // remove characters from the string until you meet a whitespace that ends the word foreach (char ConsecutiveChar in ForwardString) { if (ConsecutiveChar == ' ' && MetChar == false) { ForwardString.Substring(1, ForwardString.Length); } else if (ConsecutiveChar == ' ' && MetChar == true) { break; } else {if (MetChar == false) { MetChar = true; ForwardString.Substring(1, ForwardString.Length); }} } }