C
C#16mo ago
OkOk

✅ Simple string formatting

Why am I not able to do formatting for this specific string? What is the right way?
9 Replies
OkOk
OkOkOP16mo ago
Yes I know the dollar sign goes before the quotation but It doesn't fix it
Jimmacle
Jimmacle16mo ago
1) you're redeclaring jsonPayload 3 times which isn't valid 2) you're putting parentheses around your interpolated string like $("something") which is also wrong, no parentheses are needed
OkOk
OkOkOP16mo ago
I know, I just drew that up to illustrate Even if I put the dollar sign a step to the right it still gives an error
Jimmacle
Jimmacle16mo ago
"an error" and did you remove the parentheses?
OkOk
OkOkOP16mo ago
Yes I did, I don't see a mismatch of bracers or a misuse of backslash
Jimmacle
Jimmacle16mo ago
did you check the documentation for string interpolation? https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
$ - string interpolation - format string output
String interpolation using the $ token provides a more readable and convenient syntax to format string output than traditional string composite formatting.
OkOk
OkOkOP16mo ago
Yes I looked at a few internet guides, and i tried multiple ways of doing it, one brace or three
Jimmacle
Jimmacle16mo ago
you skipped over the one it tells you to use if you want to include a literal curly brace which is 2
OkOk
OkOkOP16mo ago
Ah thank you, that means the bracers need to be two, three then four $"{{"type":"page","body":{{"storage":{{"value":"<p>{{{a}}}</p>"}}}}"; Tricky stuff, thank you for helping me even when I was being vague
Want results from more Discord servers?
Add your server