• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

goes through each word in wordlist, find character to replace and replace it.

i have a list of words to read from.
how can i search each line, find the character to replace(in charsToReplace) and replace it(replacedChars)

public void replaceWords() throws IOException{

      char[] charsToReplace = {'a','b','e','o','i'};
      char[] replacedChars = {'4','6','3','0','1'};
      replacedChars = charsToReplace;
      BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
      BufferedReader reader = new BufferedReader(new FileReader(inputFile));

      String line;
        for(int loopList=0; (line = reader.readLine()) !=null; loopList++)
1 Solution
// loop thru all chars to replace

for (int i=0; i<charsToReplace.length; i++)
   // replace character in line

   line = line.replace(charsToReplace[i], replacedChars[i]);

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now