If the substring position (6,7) is a blank space, I want that blank space to be replaced with a hyphen (used while loop because there are many in this file). I tried the below, trying to use concatenation to link together the new line but the blank space still exists.
Right Now: ABCDEF YZ
What I need: ABCDEF-YZ
Here is a block of code:
String line= inputFile.readLine();
while(line!= null)
{
if (line.charAt(6) == ' ') {
String outputWithHyphen = line.substring(0,6) + '-' +
line.substring(7);
outputFile.println(outputWithHyphen);
}
outputFile.println(line);
line= inputFile.readLine();
}
Removed if clause, now works, really want the if clause though.
String outputWithHyphen = lineOfText.substring(0,6) + '-' +
lineOfText.substring(7);
outputFile.println(outputWithHyphen);
lineOfText = inputFile.readLine();
Thank you for all of your support!
TL;DR: Replace all hyphens with spaces in a certain position in a text file