Help with Looping through arrays in C# please
I've been looking all day online for the answer to this question, but everything I try doesn't seem to work. So I'm working on a word censurer, and I have a string of words that is turned into an array of words in line 1 of the code snippet. Everything works fine, except for this snippet of code: string[] BadWordsList = EveryBadWord.Split(' '); for (int i = 0; i <= BadWordsList.Length; i++) { string ThisWord = MalasPalabrasList[i]; CensoredText = CensoredText.Replace(ThisWord, "X"); } Debug.Log(CensoredText); When I use the text field in Unity and enter a text, it works fine, but when it gets to that part where it is supposed to replace bad words with an X (for later counting the number of Xs and knowing how many bad words were used). It marks an error that says: IndexOutOfRangeException: Index was outside the bounds of the array. manager.CheckText () (at Assets/manager.cs:173) I don't know what to do. How can I loop through the array to check the number of words that match the array and the text so it later returns a variable with all the words censured?