我想在字之間添加字符串xx
,假設這兩個字之間既不存在xx
也不存在yy
。實例:php - 如何在字符串中的兩個單詞之間插入單詞?
this house
- >this xx house
this xx house
- >this xx house
this yy house
- >this yy house
this is my house
- >this xx is xx my xx house
this yy is my house
- >this yy is xx my xx house
xx xx
- >xx xx xx
this is my house yy indeed
- >this xx is xx my xx house yy indeed
的想法是,默認情況下插入單詞xx
之間的兩個詞,如果有沒有其他xx
也不另一yy
。但是,如果在兩個單詞的MIDDLE中存在xx
或yy
,請不要添加任何內容。
如何編寫此功能?
您是否嘗試過的東西來實現自己的目標的答案? – Rizier123
爆炸的空間,循環,有點棘手 –
我試過一些子字符串,但沒有什麼 – user2580401