I’m new in .net platform and I’m curious about how can I pass js function with curly brackets as string inside StringBuilder.AppendFormat() c#.here is what I’m willing to do
StringBuilder sb = new StringBuilder();
sb.AppendFormat(@"<script>
var vm = new Vue({
el: 'main_div',
data() {
return {
proddetails: [],
}
},
created: function () {
this.proddetails = { jsonobjectplaceholder };
},
});
</script>");
sorry for stupidity if any and thanks in advance for the attention!
expecting a reasonable answer
2
Answers
Your code contains ‘AppendFormat’, did you mean to use ‘Append’?
‘StringBuilder.AppendFormat’ is used for creating a string that is formatted with an array of strings.
For instance:
The above will result in: "var1, var2, var3"
See more about StringBuilder.AppendFormat here: See Here
You can use the ‘@’ symbol as a verbatim identifier which will allow you to include multiple lines in your string.
See Here
So the code you want looks like the following:
You are using
AppendFormat
where first parameter is Formatted string. And if you wish to use curly braces inside it then you need to escape them double braces{{
and}}
. Try like below.Referene : Escape curly brace ‘{‘ in String.Format
Alternatively you can use
Append
instead ofAppendFormat
. Try like below and it will work.