for loop - How replace a phrase using charAt()? -
I'm having trouble with this method to get this sentence (word) and dang
With #!
This works in some cases, but when the input "Dang Boom Dang"
is output #! Boom da #!
. Does anyone have any suggestions on how to fix this?
Here is my code:
public static string DeleteDang (string word) {stringbuffer word sb = new stringbuffer (word); Int length = Word SB Long (); For (int i = 0; i & lt; length; i ++) {if (word.charAt (i) == 'D'} word.charAt (i) == 'D') If (word. CharAt (i + 1) == 'a' || words (i + 1) == 'a') if (words, chit (i + 2) == 'n' || words (i + 2) == 'n') If (word chaat (i + 3) == 'g' is the word word.charAt (i + 3) == 'g') wordSB = wordSB.replace (i, i + 4, "#!"); Length = word sb.line (); } String newWord = wordSB.toString (); New word returns; }
Replace all references to the word with wordSB in your loop
Delete Public String String Dang (String word) {Stringbuffer word SB = new stringbuffer (word); Int length = Word SB Long (); (Int i = 0; i & lt; length; i ++) {if (word sb.chart (i) == 'd'} word sb.chartat (i) == 'd') if ( Word SB.chart (i + 1) == 'A' || Word SB.chart (I + 1) == 'A') if (word sb.chart (i + 2) == 'n' Sb.chart (i + 2) == 'n') if (word sb.chart (i + 3) == 'g' || word sb.chart (i + 3) == 'g') word sb = Word sb. Location (i, i + 4, "#!"); Length = wordSB.length (); } String newWord = wordSB.toString (); New word returns; }
when you replace
Comments
Post a Comment