examples are nice, but they don't define the conditions. You need to give explicit rules on when you need to insert a hyphen and when you don't. Once you define the rules, coding is easy.
So, what are the rules? is any 't' character followed by a space, followed by a
word to be combined? same with 'e' followed by space? Does the case of any of the letters make a difference? What if there are multiple spaces?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors