我有格式的字符串:是否有与Java MessageFormat相当的Ruby?
Hello {0}, today is {1} and the time is {2}. Will you be eating {3}?
给予阵列["sir", "Monday", "12:00", "tacos"]
,该字符串应该被格式化为:
Hello sir, today is Monday and the time is 12:00. Will you be eating tacos?
确实红宝石有某种内置的方法做这个?还是有宝石?或者我必须更换字符串?
编辑:我想补充一点,我不允许编辑这些字符串。因此sprintf式的解决方案将无法工作。
您可以使用'%1 $ s','%2 $ s','%3 $ s'等特定参数。 – Stefan 2015-03-19 08:45:35