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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.NewLinerather 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.NewLinewould evaluate to “\n” which is the *nix new line indicator. Finally, in my viewEnvironment.NewLineis preferable from a readability perspective. It documents what this thing is logically rather than relying on you knowing the magic constants.