开发者

How to put variable value inside value of resource file

开发者 https://www.devze.com 2022-12-22 09:04 出处:网络
I have been working with resource files for a while now and I was wondering if there is some nifty way I don\'t know of yet to put variables inside a resource value.

I have been working with resource files for a while now and I was wondering if there is some nifty way I don't know of yet to put variables inside a resource value.

A simple example:

You have bought #amountOfBooksBought books.

My current way of working would be to declare two resource v开发者_如何转开发alues (for 2 labels):

BoughtBooksAmountPreTextLabel.Text : "You have bought "

BoughtBooksAmountPostTextLabel.Text : " books."

Inbetween the two labels with this text, there would be a label named BoughtBooksAmountValueLabel which contains the amount of books bought.

Is there a more elegant solution to this or is this just it?


You could put a formatted string in your resource file:

"You have bought {0} books."

Then use the formatted string with your value like this:

BoughtBooksAmountTextLabel.Text 
    = String.Format(yourResourceString, BoughtBooksAmountValueLabel)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号