简体   繁体   中英

Visual studio indent string

having this string

var commandAfterSerialize = $@"{{""LotId"":""00000000-0000-0000-0000-000000000000"",""AuctionId"":""00000000-0000-0000-0000-000000000000"",""DisableTotalSpendUpdate"":false,""AltInternetSurchargeRate"":null,""WinningBidders"":{{""{winningBidderKey}"":true,""{winningBidderKeySecond}"":false}},""Timestamp"":{timeStampUtc.Ticks},""TimestampUtc"":""{timeStampUtc:o}""}}";

is it possible to display it in better way in visual studio (for editing purpose) without modifing string itself? without inserting \r\n into it?

better formating like json

I am using visual studio 2022, c# 6.0

C# 11

Allows you to use raw string literals

Example taken from the linked resource:

var xml = """
        <element attr="content">
            <body>
            </body>
        </element>
        """;

Older C# versions

You can do something like this:

var xml = "<element attr=\"content\">"+
          "  <body>"+
          "  </body>"+
          "</element>";

Nevermind the XML, this works of course with any string content.


Outside these, I'd like to second @DavidG's comment:

If you want to embed larger, more complex JSON in your app, better to put them in a resource file

Which has further advantages, as for example you could validate the json. You can have json-specific editor behavior, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM