dimanche 1 mars 2015

The replace function in Java

I have this function in Java, that given a text, an array of words and a char, should check if the words in the "words" array exist in the text, and if they do, surround them with the given char "c".


Here's what i've come up with:



public void replaceString(BufferedReader in, BufferedWriter out, char c, String[] words){

String line_in = in.readLine();
String result = null;

while (line_in != null) {

for (int j = 0; j < words.length; j++) {

if (line_in.toLowerCase().contains(words[j].toLowerCase())) {

result = line_in.replace(words[j], bold + words[j] + bold);

}

else
result = line_in;

}

out.write(result);
out.newLine();
line_in = in.readLine();

}

}


But, for some reason, the replace method is not doing anything...


Any help would be greatly appreciated!


Aucun commentaire:

Enregistrer un commentaire