Some other solutions to this problem have been posted, but most of them require lots of looping or many lines of code. Well, I've done up a couple of simple regular expressions that solve the en/detab problem. Enjoy.
Python, 31 lines
I wrote this code because in the MacPython project we needed tools to do these types of converstions. The issue is that most Mac text editors do not support using spaces for tabs (or at least not neatly), so tabs are everywhere. But, if we get someone elses code and want to edit it, we need to convert all those spaces into tabs so that Python will read the whitespace correctly. This code is actually a modified bit stipped from my command line tool for use on OS X.
I chose regular expressions because they keep the code smaller. In fact, the longest part of this code is the comments that I added in to explain it to you when posting it for the Python Cookbook. A concise solution is always important to me.
The detab code could be done the similar to the entab code, but Python provides a function built in to do it, so I'm lazy and take what they give me. See comments for more info.