gudii9
asked on
format the code in java
Hi,
what is best way to format the code in java. when i do control shift F it is formatting OK but not removing the empty lines in between the code. How to remove empty lines of code through formatting or some shortcut to make code more clean? please advise
what is best way to format the code in java. when i do control shift F it is formatting OK but not removing the empty lines in between the code. How to remove empty lines of code through formatting or some shortcut to make code more clean? please advise
ASKER
eclipse.
i have 8 empty lines between below two lines
say Test.java class has code of two lines as below in betwen there is like 8 empty lines which i want to get rid of
System.out.println("1st line);
System.out.println("2nd line);
i have 8 empty lines between below two lines
say Test.java class has code of two lines as below in betwen there is like 8 empty lines which i want to get rid of
System.out.println("1st line);
System.out.println("2nd line);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
https://dzone.com/articles/removing-blank-lines-eclipse
followed above link but not working for me as attached. please advise
regexp.png
followed above link but not working for me as attached. please advise
regexp.png
Thanks for the points, gudii9.
Sorry I missed your previous post - not sure why/how.
If you haven't already worked it out, I think the problem you're having is you're searching for:
^\s^\n
but you should be searching for:
^\s*\n
i.e. 0 or more white-space chars followed by a newline.
Take a closer look at the webpage I linked to, and you should see this.
tel2
Sorry I missed your previous post - not sure why/how.
If you haven't already worked it out, I think the problem you're having is you're searching for:
^\s^\n
but you should be searching for:
^\s*\n
i.e. 0 or more white-space chars followed by a newline.
Take a closer look at the webpage I linked to, and you should see this.
tel2
ASKER
Regular Expression to Remove Empty Lines
The magic is using a regular expression checkbox. It uses the regular expression
^\s*\n
to find one or multiple empty lines and replaces it with ‘nothing’. That way I can clean up a full file and get rid of all empty lines.
If I do not remember the syntax of regular expressions any more, then there is help too: the dialog has content assist available:
above worked
Empty lines at appropriate places in most programming languages can be useful to aid in readability (e.g. between functions, large conditions, etc), so it would be hard to remove just the ones you want removed in an automated way. Do you really want to remove all empty lines? Why? I wouldn't recommend it.
When you say Ctrl-Shift-F, what tool are you using to write your code?
Please answer all 3 questions above and we'll take it from there.
Thanks.
tel2