Handling tab to space conversions
Posted 5 April 2004
When outputting code in a browser, or automatically formatting someone else’s code, it’s handy to be able to accurately convert tabs to spaces.
This function converts tabs to the appropriate number of spaces to preserve formatting.
A quick example:
This would produce the following output:
This is the example data:
fooobar
foooobar
fooooobar
With simple replace:
fooo bar
foooo bar
fooooo bar
With tab2space:
fooo bar
foooo bar
fooooo bar
</code>