Here is my Code

 var body="Hello World";
 var mailto = new Uri("mailto:?to=a@a.com&subject=Hello&body="+body); 
 await Windows.System.Launcher.LaunchUriAsync(mailto);

I wanted to display 'Hello' in first line & 'World' in Second line.

I tried with

  var body="Hello" + "/n" + "World"

But it is not working . How can we achieve this ?

有帮助吗?

解决方案

Try this

var body="Hello%0D%0AWorld"
var mailto = new Uri("mailto:?to=a@a.com&subject=Hello&body=" + body); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

You have to use %0D%0A in place of \n

其他提示

Followed by @Xyroid, more versitle method would be as below.

var body = "Hello" + Environment.NewLine + "World\nHere is Third Line" ;
body = System.Net.WebUtility.UrlEncode(body);
var mailto = new Uri("mailto:?to=a@a.com&subject=Hello&body=" + body); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

Please kindly see System.Net.WebUtility.UrlEncode() method to convert some text into uri-based parameters.

Try this code

StringBuilder body= new StringBuilder(); body.AppendLine("Hello "); body.AppendLine("World");

string mailBody=body.ToString();

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top