Do you have to text? Someone else already said this, but for me, blocking STBX's number and only communicating through email has done wonders for me.
Of course it's not possible for everyone. One thing that helps me is to wait 24 hours before deciding whether or not it is necessary to respond to anything.
Texting just lends itself to a speedier communication and that is where I think it's easy to get caught up and engage.
If possible, switch to email only communication. If not possible, sit on your hands as long as possible. Silence is more powerful than any answer you can give.
And remember, you DO NOT HAVE TO ANSWER EVERY TEXT OR EMAIL. You just don't. It's not required. And they always have a way to make nothing into something so easily. You start with one reply and next thing you know you are in a full blown back and forth that can last for days.
Silence is the most powerful response, but if you must respond, say it once and only once. Don't even respond to the next message with a "refer to the last email" ůsay nothing. Saying it once is enough. Talk to him like you would talk to a cashier at the grocery store, no emotion. One and done.