AnswerBun.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!

Related Questions

Output is not shown in C

1  Asked on December 13, 2021 by cally

     

Have to print to screen for program to work

1  Asked on December 13, 2021

 

why ” is not pushed to stack to indicate the end of string?

0  Asked on December 13, 2021 by user11224591

   

Printing wrong text in list in Python

1  Asked on December 13, 2021 by n1ng4

         

Getting and saving application scope variable in Tomcat

3  Asked on December 13, 2021 by woodsman

   

Issue with Ansible Check and Diff Mode

1  Asked on December 13, 2021 by sunder

   

Java HashMap in Python Code throwing Error

1  Asked on December 13, 2021 by pritiraj

     

I am a little bit confused by the super().__init__()

4  Asked on December 13, 2021 by nick-yang

   

Formset not showing in Django 3

0  Asked on December 13, 2021 by ethan-roman

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP