我有以下变量:多行字符串文本格式给我的错误 - 输入字符串的不正确的格式
var setting =
[email protected]"worker_processes {{0}};
worker_rlimit_nofile {{1}};
error_log logs/{{2}} {{3}};
events
{{
worker_connections {{4}};
multi_accept {{5}};
}}";
当我做了以下String.Format()
操作:
return string.Format(setting,
this.worker_processes,
this.worker_rlimit_nofile,
this.error_log_file,
this.error_log_level,
this.worker_connections
this.multi_accept ? "on" : "off");
我收到以下错误:输入字符串格式不正确。
有什么建议吗?
编辑 - 固定
感谢乔恩斯基特,我已经在这个解决方案抵达,而无需使用String.Format()
:
return
[email protected]"worker_processes { this.worker_processes };
worker_rlimit_nofile { this.worker_rlimit_nofile };
error_log logs/{ this.error_log_file } { this.error_log_level };
events
{{
worker_connections { this.worker_connections };
multi_accept { (this.multi_accept ? "on" : "off") };
}}";
如果你使用的是C#5.0(根据你的标签)'$ @'根本不应该工作 - 并且不清楚你为什么试图使用它。你究竟在努力实现什么? –
注意:有6个占位符和4个参数...(这应该给出不同的错误 - 所以假设是复制粘贴错误)。 –
@JonSkeet对不起,我打算说我正在使用C#4.5。我有一个为nginx配置文件保存“模板”的变量。然后我想用设置中的值替换占位符。 – Latheesan