0

I dont know whats happening here but I cant join two strings together with a newline between them. I use the following code in my Windows Store App to open the email client and prefill an email:

String recipient = "me@here.com";
String Bodymsg = "Line One" + Environment.NewLine + "Line Two";
String SubLine = "Report Fault";
String BodyText = "mailto:?to=" + recipient + "&subject=" + SubLine + "&body=" + Bodymsg;
var mailto = new Uri(BodyText);
await Windows.System.Launcher.LaunchUriAsync(mailto);

This works fine but the body comes out like this.

Line OneLineTwo

What I want to get is

Line One  
Line Two

I have tried using "/r/n" and "/n" instead of Environment.NewLine but it gives the same effect. Any ideas where I'm going wrong?

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
Mark Barr
  • 159
  • 2
  • 12
  • I would recommend using stringbuilder for this. It will be cleaner, but more importantly it will deliver better performance. An example of stringbuilder for this would be: StringBuilder builder = new StringBuilder(); builder.AppendLine("This will be a full line"); builder.Append("this will be started at the end of the last string which in this case is the beginning of a new line") .AppendLine("You can also use the fluent format to improve readability"); – Nick Feb 07 '15 at 00:08
  • Thanks for pointing me in the right direction Guys Didnt think of searching for Mailto questions rather than string questions the following works String Bodymsg = "Line One" + "%0D%0A" + "Line Two"; – Mark Barr Feb 07 '15 at 07:49

2 Answers2

0

The newline character is \n and not /n, have you tried:

String Bodymsg = "Line One\nLine Two";

Xeaz
  • 340
  • 4
  • 13
0

Without seeing more of your code and how you're using the email, I'd say it might be formatted in HTML. Try concatenating the two strings with a <BR>.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • That is my full code I click a button and it runs the code above which opens windows 8 email program and composes the email. The problem is in the message body where whatever I try I cant get it to drop lines – Mark Barr Feb 07 '15 at 07:43