-1

我需要在句子的最后一个单词之前添加一个单词。

例子 :

   t1 = "Top Senior Players" OR t1 = "Top Athlete" OR t1 = "Youngest Athlete"
   t2 = "Hockey"  OR t2 = "Cricket" etc.

我希望得到像这样的输出

   var game = "Top Senior <t2> Players" OR t1 = "Top  <t2> Athlete" OR t1 = "Youngest  <t2>  Athlete"

它应该在最后一个单词之前的单词处。

4

2 回答 2

3
t1.split(" ").insert(-2,t2).join(" ")
于 2012-10-09T10:48:06.927 回答
2
a = 'first third'
a.split(' ').insert(-2, 'second').join(' ')
=> "first second third"

a = 'first'
a.split(' ').insert(-2, 'second').join(' ')
=> "second first"
于 2012-10-09T10:45:25.090 回答