These darn tabs often cause problems. Who invented them!?
Ok, I've dealt with tab problems before, but then I usually created a workaround for the situation. Now I would like to have a general solution to convert tabs to spaces and vice versa.
The first thought is often: "What should be so hard about that! You take the tab length and replace each tab with this number of spaces". But it is not that simple.
Suppose a user has set a tab length to 4. If he now writes: "This is a test"
Speed optimization of latest Nine's code:
In StringInStr() and StringReplace() use CaseSense=1, this is MUCH faster
Func _TabsToSpaces($sString, $iTabLen = 8)
Local $iMod, $iSpaceLeft
Local $iTabPos = StringInStr($sString, @TAB)
$iMod = Mod($iTabPos, $iTabLen)
$iSpaceLeft = $iMod ? $iTabLen - $iMod : 0
$sString = StringReplace($sString, Chr(9), _StringRepeat(" ", $iSpaceLeft + 1), 1)
$iTabPos = Strin