quote and quotes in a string (leaving " or #39; in the View)

Asked

Viewed 703 times

0

I’m trying to put the following text in a string, but I can’t... when I can’t find the wrong double quotes in the arroba... I’m going crazy. Can someone help me?

,{ "@type": "Listitem", "position": 2, "item": { "@id": "http://www.enderecosite.com", "name": "description Xyz", "image": "http://addressite/Tumb-sharefacebook.jpg" } }

I’m trying something like:

string TextoComplicado = ",{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "http://www.enderecosite.com",
"name": "descrição xyz",
"image": "http://enderecosite/tumb-compartilhamento-facebook.jpg"
}
}";

This variable will be placed inside a script tag in my View:

<script type="application/ld+json"> @*Apenas detalhes do Imovél?*@
   @Model.TextoComplicado 
</script>

If I put ' (single quotes) is printed #39; instead of quotation marks

If put " is printado ecomercial quot; in place of quotation marks

How to solve this?

2 answers

3


Simple quotes is for char, so the #39 (ASCII code).

And double quotes is for starting or finishing a string. If you need to place one in the middle of the string, use an escape character: \:

Example:

string x = """; //Erro

string y = "\""; //OK

Your case would look something like this:

string teste = " \"@type\": \"ListItem\"";

Edit:

Try to use the System.Net.WebUtility.HtmlDecode(string); so that the string value is not displayed as Html code.

Example:

<script type="application/ld+json"> @*Apenas detalhes do Imovél?*@
   @System.Net.WebUtility.HtmlDecode(Model.TextoComplicado) 
</script>
  • Valew Rovan, but the output on my page is being &quot instead of quotation marks

  • I saw this... a moment that I’m going to hit... that’s already a matter of html...

  • You’re right (it’s html). In the view I used @Html.Raw(Model.Textcompleted) and boom! It worked!!! Valew!

  • 1

    Htmldecode tbm Ok! Even valew

  • If you’ve solved it, don’t forget to mark it as an answer. Vlw

1

Do it that way :

        string TextoComplicado =
            ",{\r\n\"@type\": \"ListItem\",\r\n\"position\": 2,\r\n\"item\": {\r\n\"@id\": \"http://www.enderecosite.com\",\r\n\"name\": \"descrição xyz\",\r\n\"image\": \"http://enderecosite/tumb-compartilhamento-facebook.jpg\"\r\n}\r\n}";

Example here: https://dotnetfiddle.net/1a05FX

  • Thanks @Thiago. I tried it here, but it’s printing &quot; instead of double quotes

  • try also to use Htmldecode, see if it solves.

  • https://msdn.microsoft.com/en-us/library/aa332854%28v=vs.71%29.aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.