字符串格式的描述性文字 [英] String Format descriptive text
问题描述
是否有可能一些描述性文本添加到字符串格式说明
例如:
的String.Format({0:用的名字}不在家,person.ForeName);
在这个例子用的名字
添加为说明
以上语法显然是不正确的,但只是为了显示这个想法。
的原因,我问,是因为在我的情况的字符串是在资源文件,因此在资源文件,你目前仅见
{0}不在家
在某些情况下,这是很难把握什么样的背景下 {0}
是
编辑:
在C#6串插在 $
运营商已经出台,因此的String.Format
不需要了:
${} person.ForeName不在家;
我们通常把意见变成我们的资源文件,例如 {0} =用名字
。
那么任何人谁可能会被翻译字符串知道什么 {0}
表示,并可以相应转换。
此外,如果您使用ReSharper的,你可以在输入时要添加您的字符串资源的同时评论。
Is it possible to add some descriptive text to a string format specifier?
Example:
string.Format ("{0:ForeName} is not at home", person.ForeName);
In the example ForeName
is added as description.
The above syntax is obviously incorrect, but just to show the idea.
The reason I am asking, is because in my case the strings are in a resource file, so in the resource file you currently only see
{0} is not at home
in some cases it is hard to grasp what the context of {0}
is.
EDIT:
In c# 6 string interpolation with the $
operator has been introduced, so string.Format
is not needed anymore:
$"{person.ForeName} is not at home";
We usually put comments into our resources file e.g. {0} = Forename
.
Then anybody who might be translating the string knows what {0}
represents and can translate accordingly.
Also if you use ReSharper, you can enter the comment at the same time when you are adding your string to resources.
这篇关于字符串格式的描述性文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!