How can I add line breaks using the SetText method?
I tried Clipboard.SetText("eee \n xxxx");
but it doesn't give me the expected result when I paste the clipboard data in the notepad.
Expected result:
eee
xxxx
How can I accomplish this?
I know this is a bit late... but I often use StringBuilder for memory and performance reasons and it' has a very handy AppendLine() method.
Windows uses CR+LF pairs to indicate a new line. This equates to "\r\n"
in C#. However, you are just sending "\n"
, i.e. a single LF rather than a CR+LF pair.
Use Environment.NewLine
rather than of "\n"
. This is the idomatic way to spell "\r\n"
in C#. As a bonus, if you ever ran your code on a *nix platform, Environment.NewLine
would evaluate to "\n" which is the *nix new line indicator. Finally, in my view Environment.NewLine
is preferable from a readability perspective. It documents what this thing is logically rather than relying on you knowing the magic constants.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With