-1

So I am trying to export some text from a Visual C# Windows Form string to an email to be sent, via mailto protocol (e.g. mailto:email@goldesanmartin.com), and I found out that I had to change my line breaks ("\r\n") to "%0D%0A" in order to be recognized by the protocol. I'd need the equivalent to a quotation mark for this. And also it would be good if you could tell me where to find any other special characters forbidden and their equivalents, in order to not be asking this again anytime. Thanks in advance

OrangeWall
  • 79
  • 1
  • 8

4 Answers4

3

Looks like you need to encode part of your url. You can use the HttpUtility class to do the job for you.

// you will need to reference System.Web
HttpUtility.UrlEncode("\r\n") => "%0d%0a"
Xiaoy312
  • 14,292
  • 1
  • 32
  • 44
  • From the documentation of HttpUtility you linked to: *"The HttpUtility class is used internally by the HttpServerUtility class, whose methods and properties are exposed through the intrinsic ASP.NET Server object. Additionally, the HttpUtility class contains encoding and decoding utility methods that are not accessible from the Server. To encode or decode values outside of a web application, use the [WebUtility](https://msdn.microsoft.com/en-us/library/system.net.webutility(v=vs.110).aspx) class."* – Scott Chamberlain Aug 14 '15 at 21:27
2

To make your life easier, System.Web has a built-in function that saves your time & do everything for you.

using System.Web;

string mailStr = HttpUtility.UrlEncode("mailto:email@provider.com");

Now you can use it without worrying about anything.

Alaa Salah
  • 1,047
  • 3
  • 12
  • 28
  • System.Web.HttpUtility is not supposed to be used outside of a ASP.NET enviorment. For non ASP.NET applications you should use [System.Net.WebUtility](https://msdn.microsoft.com/en-us/library/system.net.webutility(v=vs.110).aspx) instead (See my comment to Xioy312's answer) – Scott Chamberlain Aug 14 '15 at 21:28
1

That looks like URL encoding. %## specifies a hexadecimal number that corresponds to an ASCII character code. For a single quote ('), that should be %27. You can find ASCII tables pretty easily through a web search.

Jacob
  • 77,566
  • 24
  • 149
  • 228
0

Well, Quotation Mark equivalents are here: http://www.fileformat.info/info/unicode/char/0022/index.htm

I think this will solve your problem, You need to escape the character or using double quotation! from here you may find the links:

Quotation Mark equivalents here: http://www.fileformat.info/info/unicode/char/0022/index.htm

well, the problem being discussed already multiple times. you need to escape the character or using double quotation! here you find few useful links:

How can I put quotes in a string?

https://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.90).aspx

Hope this helps!

Community
  • 1
  • 1
narainsagar
  • 1,079
  • 2
  • 13
  • 29