string template = @"
{
argument1 = ""{0}"";
开发者_如何学C argument2 = {1};
}";
When I format it as a usual string with string.Format, naturally i get an exception that the input string was not in correct format. I tried escaping the arguments as it is recommended in msdn documentation, like "{{0}}" and even "{{{0}}}", but i still get the same exception. Any ideas on how to format such a string?
Thanks!
P.S.[edit] my original string is for generating a WCAT scenario file:
string scenarioHeaderTemplate = @"
scenario
{{
name = ""WCAT Scenario"";
warmup = {0};
duration = {1};
cooldown = {2};
default
{
version = HTTP11;
setheader
{
name = ""Connection"";
value = ""keep-alive"";
}
statuscode = 200;
close = ka;
}
}}";
and it throws if i try string.Format(scenarioHeaderTemplate, 10, 10, 10);
The problem is the open and close braces. You need to quote those, or Format will think you're begining a parameter specifier.
string template = @"
{{
argument1 = ""{0}"";
argument2 = {1};
}}";
精彩评论