I think verbatim (multiline) strings in C# is a really great idea. I used to copy SQL from/to code minimizing typo errors.
Actually I need to render some javascript and I hit the wall.
The need of double quotes can be partially avoided using apostrophes in javascript, but in case you need format strings you also have to escape curly brackets:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.GetType().FullName, @"
<script type=""text/javascript"">
$(document).ready(function() {
$('#my_button').click(function() {
alert('Handler for .click() called.');
});
});
</script>
");
looks like with string.Format
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.GetType().FullName, string.Format(@"
<script type=""text/javascript"">
$(document).ready(function() {{
$('#{0}').click(function() {{
alert('Handler for .click() called.');
}});
}});
</script>
"), buttonName);
I do not want to compromise speed of formating execution just to have easier life while coding using some sort of formating string preprocessing.
I hope there is some smart and easy way. Just do not want to reinvent wheel…
Thanks
Nope, just this incredibly slow and klunky way:
`