arrow_back How can I make the number of gaps in the substitution equal to the length of the word or make a recalculation so that the substitutions do not collapse?

1 vote
Good afternoon!
You need to replace with empty/delete words from the array in the string.
I find the initial indexes and then replace them with a blank, but my replacements mangle the text - how can this be corrected?
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();

Thank you.


Need to clarify:
1. What does it mean
they twist the text
? What are you supplying to the input? What are you getting out? What is it supposed to be?
2. What are the Lexemes classes? StringInStringSearch?
Dmitry Roo ,
On the input of something like this:
Operator of
'/': if R = 0 then Error else SetDisplay(Operand / R);
if (Longint(Location) <> Longint(ALocation)) or

Exit: Line size is the same. empty spaces instead of words from the array
1.Say one word of 10 characters is found 5 times, the second of 5 times say 3.They have indices.But after replacing the first idx string changes. If the words were of the same length it would be no problem to replay them to an empty space, but the length changes, not what is needed is overwritten...
I'm thinking maybe I can do it through matchez.
1.input a string at the output should ideally be a string of the same length, only with the words replaced with a blank
2.lexemes, an archive of words that are searched for
String in Church is a class that searches for words in text
Amigo2019 , use the "reply" button, sometimes it helps.
1. Just write down your test data:
For example: ABC -> CDE (should be FGH)
2. Just attach their code.

1 Answer

0 votes
Expand the loop, in which you go through (by j) occurrences of the keyword. If you delete from the end, the indexes will not move out.