Answer the question
In order to leave comments, you need to log in
How to make the number of gaps in the replacement equal to the length of the word or do a recalculation so that the replacement does not collapse?
Good afternoon!
It is necessary to replace with emptiness / remove words from the array in the string.
I find the initial indexes, and then I replace it with a void, but my replacements distort the text - how can I fix this?
ublic class Keywords {
public static String searchAndReplaceKeywords(String afterD){
String codeAfterSC="";
Lexemes instanceLexemes = new Lexemes();
StringInStringSearch instanceSearch = new StringInStringSearch();
StringBuilder builder=new StringBuilder(afterD);
for (int i = 0; i < instanceLexemes.stringKeywords.length; i++) {
String word = instanceLexemes.stringKeywords[i];
int size=word.length();
System.out.println("Keyword : " + word + " finded in places: " + instanceSearch.findString(afterD, word));
List<Integer> list=instanceSearch.findString(afterD, word);
for(int j=0;j< list.size();j++){
int indexDelete=list.get(j);
int end=indexDelete+size;
builder.replace(indexDelete,end," ");
}
}
return codeAfterSC=builder.toString();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question