Replacing multiple new lines in a file with just one

后端 未结 5 2008
轻奢々
轻奢々 2021-01-22 12:00

This function is supposed to search through a text file for the new line character. When it finds the newline character, it increments the newLine counter, and when

5条回答
  •  离开以前
    2021-01-22 12:56

    if newline > 2     
    

    That should be greater than or equal to if you want to get rid of the second line. Also you have newline strarting at one, then being incremented to two then reset to zero. Instead I recommend replacing the count with a boolean like

    boolean firstNewlineFound = false
    

    Then Whenever you find a newline set it to true; whenever it is true, delete onenewline and set it back to false.

提交回复
热议问题