# Replace new Line Character by \\n in Java

**URL:** <https://forum.pinegrow.com/t/replace-new-line-character-by-n-in-java/6308>\
**Category:** General\
**Created:** [February 23, 2022, 11:10am UTC](https://forum.pinegrow.com/t/replace-new-line-character-by-n-in-java/6308 "2022-02-23T11:10:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitdixit](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/ankitdixit/32/3428_2.png) [@ankitdixit](https://forum.pinegrow.com/u/ankitdixit)\
**Post date:** [February 23, 2022, 11:10am UTC](https://forum.pinegrow.com/t/replace-new-line-character-by-n-in-java/6308/1 "2022-02-23T11:10:37Z")

</div>

Hello Everyone, I am facing some issues while I’m coding an IDE. Let’s say I have the [Hello, World](http://wiki.freepascal.org/Hello,_World) Pascal program on a string:

```auto
String sourceCode = "program Hello;\nbegin\nwriteln ('Hello, world.');\nend.";

```

If I do System.out.println(sourceCode); the output shows:

```auto
program Hello;
begin
writeln ('Hello, world.');
end.

```

reat, but I want to show new lines as `\n` . I tried:

```auto
sourceCode = sourceCode.replaceAll(System.lineSeparator(), "\\n");

```

But then `System.out.println(sourceCode);` outputs:

```auto
program Hello;nbeginnwriteln ('Hello, world.');nend.

```

How can I achieve that? Full demo:

```auto
public class PrintPascalHelloWorld {
    public static void main(String[] args) {
        String sourceCode = "program Hello;\nbegin\nwriteln ('Hello, world.');\nend.";
        System.out.println(sourceCode);
        sourceCode = sourceCode.replaceAll(System.lineSeparator(), "\\n");
        System.out.println(sourceCode);
    }
}

```

Can anyone suggest me? I’m able to compile and run the program using by [interviewbit](https://www.interviewbit.com/online-java-compiler/) online compiler.

---

<div class="post-metadata">

**Author:** ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)\
**Post date:** [February 23, 2022, 1:56pm UTC](https://forum.pinegrow.com/t/replace-new-line-character-by-n-in-java/6308/2 "2022-02-23T13:56:31Z")

</div>

Hi @ankitdixit,  
Hopefully someone in the forum can help out, but I’m not sure this is the right place for this type of question. This forum is for questions, issues, and topics concerning the Pinegrow Web Editor.  
Thanks for keeping it on topic,  
Bob
