Is there any way to insert an empty line in a string type variable.

string textFile = "abc";

textFile = textFile + string.Empty;
textFile = textFile + "def";

This is what I'm trying. But the string.Empty has no effect.

This also neither works textFile = textFile + "\n";

Any suggestions?

Recommended Answers

string.Empty is the empty string, not an empty line. "\n" is a string that contains a newline character. If you want an empty line, you need two newline characters.

Jump to Post

So I need to do this

textFile = textFile + "\n\n"; ?

Newline characters separate lines.

Jump to Post

All 5 Replies

string.Empty is the empty string, not an empty line. "\n" is a string that contains a newline character. If you want an empty line, you need two newline characters.

So I need to do this

textFile = textFile + "\n\n"; ?

string.Empty is the empty string, not an empty line. "\n" is a string that contains a newline character. If you want an empty line, you need two newline characters.

So I need to do this

textFile = textFile + "\n\n"; ?

Newline characters separate lines.

Thanks got that working...

Newline characters separate lines.

The first newline moves you to the beginning of a new line.
The second newline moves you to the beginning of yet another new line. That way you get an empty line between two "string" lines. If you know how a typewriter works you will get the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.