# Use Portable Newline
# Description
This rule replaces any occurrences of '\n' with '%n'.
For example 'String.format("\n\n")' is replaced by 'String.format("%n%n")'.
# Benefits
The benefit of this approach is that '%n' is portable across platforms.
# Tags
# Code Changes
Pre
public class TestStringFormatLineSeparatorRule {
public String testStringFormatLineSeparator01() {
return String.format("\n\n");
}
public String testStringFormatLineSeparator02() {
return String.format(Locale.GERMAN, "\n\n");
}
public String testStringFormatLineSeparator03() {
return String.format("\r\n\r\n");
}
public String testStringFormatLineSeparator04() {
return String.format(Locale.GERMAN, "\r\n\r\n%n");
}
}
Post
public class TestStringFormatLineSeparatorRule {
public String testStringFormatLineSeparator01() {
return String.format("%n%n");
}
public String testStringFormatLineSeparator02() {
return String.format(Locale.GERMAN, "%n%n");
}
public String testStringFormatLineSeparator03() {
return String.format("%n%n");
}
public String testStringFormatLineSeparator04() {
return String.format(Locale.GERMAN, "%n%n%n");
}
}
Use a Java Refactoring Tool
No license required
You can review this refactoring on your code without a license by installing jSparrow to your Eclipse IDE. Install the plug-in from Eclipse IDE: Eclipse Marketplace.
System-wide Refactoring
Do you want to automate this refactoring (and many more) to your system-wide code? The automatic application of this system-wide refactoring can be unlocked by acquiring your jSparrow license.