I'm trying to delete characters from a string with a for loop. I'm expecting a trace of 'Cats' but I'm keep getting 'Ctswsm'. I'm not sure what's going on. Any help would be appreciated
deleteChar deletes all instances of the character passed in, because split breaks the string into an array of strings delimited by the character given. Then it rejoins that array with no delimiters.
So, following the execution of your program:
str1 = "Cats are awesome".
str1.charAt(4) = " ".
deleteChar("Cats are awesome", " ")
str1 = "Catsareawesome"
str1.charAt(5) = "r"
deleteChar("Catsareawesome", "r");
str1 = "Catsaeawesome"
str1.charAt(6) = "a"
deleteChar("Catsaeawesome", "a")
str1 = "Ctsewesome"
str1.charAt(7) = "o"
deleteChar("Ctsewesome", "o")
str1 = "Ctsewesme"
str1.charAt(8) = "e"
deleteChar("Ctsewesme", "e")
str1 = "Ctswsm"
i = 9; i > str1.length.
Thanks. I figured that I need to change the value of i so that it starts at the correct position after a letter is deleted. And that works with 1 line text, but if I want to load multiple line text, at times, variable i doesn't subtract correctly for some reasons. I'm using Flash Builder to debug as well as to build the project, but I've also included the source folder with the text file I'm testing with.
The miscalculated of i starts after "The world loves dog!". If you open the source file and play with it, you will see that i is calculated to the wrong value for some reason.