1

I have the following HTML code:

<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href="mailto:[email protected]">[email protected]</A></P>

and of course when I try to pass it to string it gives me error:

 string s =  "<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href="mailto:[email protected]">[email protected]</A></P>";

Is there a way I could just take that HTML and convert it to a .NET equivalent, preferably without changing the format?

thanks in advance.

7 Answers 7

3

Escape the quotes:

string s =  "<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href=\"mailto:[email protected]\">[email protected]</A></P>";
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you just have to escape the quotes:

 string s =  "<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href=\"mailto:[email protected]\">[email protected]</A></P>";

In C# " denotes the beginning or end of a string, to use a " inside a string you need to 'escape' it like this \". You may also use verbatim string literals of the format

string s = @"this is a string with "" <-- a quote inside";

Comments

0

Try this:

string s = "<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href='mailto:[email protected]'>[email protected]</A></P>";

You can not use the double quotes inside the string without escaping them. Or use the version I posted.

Comments

0
string s =  "<P>Notes:&nbsp;&nbsp; Mails: <BR> &nbsp; 1. <A href=\"mailto:[email protected]\">[email protected]</A></P>";

You have to escape the quotes with a slash "\".

Comments

0

There's no string literal in C# where you don't have to escape double quotes.

var str1 = "<A href=\"mailto:[email protected]\">";
var str2 = @"<A href=""mailto:[email protected]"">";

Comments

0
string s = "<P>Notes:&nbsp;&nbsp;Mails:<br />&nbsp;1.<A href=\"mailto:[email protected]\">[email protected]</A></P>";

Comments

0

You have several options:

For compile time support, you can escape quotes with \", as demonstrated so many times by others (so I'll not repeat), you can use a literal string @"..." where you can escape quotes with "", or you can paste your string in a resource file and let Visual Studio handle the escaping for you.

Alternately, you can often get by if you replace the double quote for a single; however, this can sometimes be a problem if your string contains JavaScript, as having two types of quotes at hand may be a necessary evil.

At run time you can avoid escaping by reading the text from a file, database, or some other resource; however, I get the impression this is not your intent.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.