I struggle with that some in real life, not as much on the forums because I have more time to think about what I want to say; I often wait a few hours or even days if I'm considering posting something contentious. I try to hold back offline as well but don't always have the luxury. Stress tends to limit my filter as well.
Prayer helps though! I often start the day asking God to help me say what He wants me to say, and do what He wants me to do.
Another thing I try to remember is that my comments can be 100% correct and still 0% helpful. Sometimes there are more important things than being "right". Proverbs 15:23 is a good verse:
A man has joy by the answer of his mouth, And a word spoken in due season, how good it is!