在模板替换字符串最快的方法 [英] fastest way to replace string in a template
问题描述
我有一些模板字符串
这是我的{0}模板{1}字符串
this is my {0} template {1} string
我打算把用户的值用的String.Format()
。
该字符串实际上是不再那么为了提高可读性我使用的:
The string actually is longer so for readability I use:
这是我的{goodName1}模板{goodName2}字符串
this is my {goodName1} template {goodName2} string
然后与string.replace
每个参数与它的价值。
And then String.Replace
each parameter with its value.
我怎样才能获得最高的性能和可读性?
How can I get the highest performance and readability?
也许我不应该在一个文件中这个模板(如现在),但动态地concatanating一个字符串生成器,并在需要时添加PARAMS建设呢?虽然它的可读性。 ?
Maybe I should not have this template in a file (as now) but dynamically build it by concatanating to a string builder and adding the params when required? Although it's less readable.
什么是我的其他选项
推荐答案
从阿特伍德:<一HREF =http://www.codinghorror.com/blog/archives/001218.html>它。只是。不。此事。
这篇关于在模板替换字符串最快的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!