質問

I'm trying to format a String using the String.Format function, but my double quotes keep getting replaced by the HTML safe version of this ("). Needless to say this is not the result I would expect.

My current code looks like this

string String= String.Format("{0}: {{ name: \"{1}\"}}", node.Category, node.Name);
// Output ==> SomeCategory: { name: "SomeName" }

I've tried replacing the " by actual quotes in the output, but that also didn't work.Is there some voodoo I can use to fix this?
Thanks in advance!

役に立ちましたか?

解決

This is not caused by String.Format(), more likely it is caused by whatever you use to view the data, or by something that happens before you view the data.

Judging from your format string it looks like you're trying to create a JSON string to return (possibly from a service). There is a big chance something will HTML encode your string on it's way to the client. The problem lays there, not in your string formatting, and thus trying to fix it there will not work.

他のヒント

Try to use HTML decode and encode That way you can turn them in actual quotes.

HttpUtility.HtmlDecode

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

Stackoverflow source: " instead sign of quote (")

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top