TransWikia.com

How to keep the ```n``` char in a string in java without actually creating a new line?

Stack Overflow Asked by Adi shukla on August 12, 2020

I have a string of csv data. For some fields, the data has n char in it which is disrupting the csv file. I want to keep that n char in the data without creating a new line. Is there some way to escape the creation of a new line and keeping the char as well in java. A sample would be ->

Name,Description
Test,HellonWorld

Now when I will open this csv file in a csv viewer there will be a new line there. I can’t remove the n char and replace it with "". So is there some way to keep it and escape the functionality of n char in java?

3 Answers

n a newline character. To use it as a normal statement you may use it as "\n". to say:

Hello\n World

Answered by Anushka on August 12, 2020

Try to put one more backslash. Like \n

Answered by Radek on August 12, 2020

n is special. It is an escape sequence that stands for a newline. You need to escape it in a string literal in order for it to be actually interpreted the way you want. Append a before it so it looks like this:

\n

Answered by AdilOoze on August 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP