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?
Never ascribe to malice that which can be adequately explained by stupidity.
Check out java.util.regex.Pattern in combination with java.util.regex.Matcher. In short:
- create a Pattern with the right pattern
- get a Matcher from the pattern for the input string - use the matcher to search once (hint: the method is not called search but still quite similar)
- use the start of the match as the index of the found match