Pet*_*ter 6 .net resource-files
我一直在使用资源文件一段时间,我想知道是否有一些漂亮的方式我不知道还没有将变量放在资源值中.
一个简单的例子:
你已经购买了#amountOfBooksBought书籍.
我目前的工作方式是声明两个资源值(对于2个标签):
BoughtBooksAmountPreTextLabel.Text:"你买了"
BoughtBooksAmountPostTextLabel.Text:"书籍".
在带有此文本的两个标签之间,会有一个名为BoughtBooksAmountValueLabel的标签,其中包含购买的书籍数量.
是否有一个更优雅的解决方案或这只是它?
And*_*are 16
您可以在资源文件中放置格式化的字符串:
"You have bought {0} books."
Run Code Online (Sandbox Code Playgroud)
然后使用带有您的值的格式化字符串,如下所示:
BoughtBooksAmountTextLabel.Text
= String.Format(yourResourceString, BoughtBooksAmountValueLabel)
Run Code Online (Sandbox Code Playgroud)