我有一个格式的字符串:
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?
Ruby 是否有某种内置方法可以做到这一点?还是有宝石?还是我只需要更换字符串?
编辑:我想补充一点,我不允许编辑这些字符串。因此,类似 sprintf 的解决方案将不起作用。