I am reading each line in the text file, do some with the file and write back to same file using Java. And, position(index) of each value in the line is important. So I need to preserve the location of the each value.
How do I remove a “space” character at specific location(index)?
Say, below is the line that I read,
.... ABC 123.... --There are 3 spaces between ABC and 123
Basically, I want to make the above line written as 2 spaces between ABC and 123.
At first, I was just using replaceAll of String but that just shift the the values to right by one and still 3 spaces. So, I figure I need more than just replaceAll.
Now, I am getting a position of where ABC is found and just trying to remove that 1 space.
If you want to remove a single character, just use
StringBuilder.deleteCharAt.I explicitly advise you not to do the
substringapproach.