String original = "Hello\r\nWorld!"; String converted = StringUtil.convertLineSeparators(original, "\n"); System.out.println(converted); // Output: Hello\nWorld!
String original = "First line\nSecond line\r\nThird line"; String converted = StringUtil.convertLineSeparators(original, "\r\n"); System.out.println(converted); // Output: First line\r\nSecond line\r\nThird lineIn this example, we have a string with a mix of Unix-style and Windows-style line separators. We use the StringUtil.convertLineSeparators() method to convert all line separators to the Windows format ("\r\n"). This method is part of the IntelliJ IDEA platform, which is a Java-based integrated development environment. Therefore, the StringUtil class is part of the IntelliJ IDEA libraries.