Jump to content

How do I print new line characters from a text file

Simple question I am reading a line from a text file which contains \n's and when I print the string it doesn't print the \n as a new line but as "\n" how do I change this into a newline. 

 

 

Line 1 is what I get, Lines 2-5 is what I want. (I did this manually to get the desired output)

image.png.1897f0e3421f3db23439c609d8c7d769.png

 

EDIT: Just found out why it's doing it, it is turning /n into //n so I need to find //n and replace it with /n, any suggestions on how to do this

The owner of "too many" computers, called

The Lord of all Toasters (1920X 1080ti 32GB)

The Toasted Controller (i5 4670, R9 380, 24GB)

The Semi Portable Toastie machine (i7 3612QM (was an i3) intel HD 4000 16GB)'

Bread and Butter Pudding (i7 7700HQ, 1050ti, 16GB)

Pinoutbutter Sandwhich (raspberry pi 3 B)

The Portable Slice of Bread (N270, HAHAHA, 2GB)

Muffinator (C2D E6600, Geforce 8400, 6GB, 8X2TB HDD)

Toastbuster (WIP, should be cool)

loaf and let dough (A printer that doesn't print black ink)

The Cheese Toastie (C2D (of some sort), GTX 760, 3GB, win XP gaming machine)

The Toaster (C2D, intel HD, 4GB, 2X1TB NAS)

Matter of Loaf and death (some old shitty AMD laptop)

windybread (4X E5470, intel HD, 32GB ECC) (use coming soon, maybe)

And more, several more

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, grimreeper132 said:

Simple question I am reading a line from a text file which contains \n's and when I print the string it doesn't print the \n as a new line but as "\n" how do I change this into a newline. 

 

 

Line 1 is what I get, Lines 2-5 is what I want. (I did this manually to get the desired output)

image.png.1897f0e3421f3db23439c609d8c7d769.png

 

EDIT: Just found out why it's doing it, it is turning /n into //n so I need to find //n and replace it with /n, any suggestions on how to do this

Sorted, encase anyone was wondering it's

string.replace("\\n", "\n");

The owner of "too many" computers, called

The Lord of all Toasters (1920X 1080ti 32GB)

The Toasted Controller (i5 4670, R9 380, 24GB)

The Semi Portable Toastie machine (i7 3612QM (was an i3) intel HD 4000 16GB)'

Bread and Butter Pudding (i7 7700HQ, 1050ti, 16GB)

Pinoutbutter Sandwhich (raspberry pi 3 B)

The Portable Slice of Bread (N270, HAHAHA, 2GB)

Muffinator (C2D E6600, Geforce 8400, 6GB, 8X2TB HDD)

Toastbuster (WIP, should be cool)

loaf and let dough (A printer that doesn't print black ink)

The Cheese Toastie (C2D (of some sort), GTX 760, 3GB, win XP gaming machine)

The Toaster (C2D, intel HD, 4GB, 2X1TB NAS)

Matter of Loaf and death (some old shitty AMD laptop)

windybread (4X E5470, intel HD, 32GB ECC) (use coming soon, maybe)

And more, several more

Link to comment
Share on other sites

Link to post
Share on other sites

If you want the reason as for why this is happening it is because your \n are not real \n they are literal text of a slash plus and n. For the string object in memory it manually escape the slash to NOT count it as a new line so it's actually \\n and not \n.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×