문제

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