Space indentation users, unite! We must fight against all the lowly tab users!
Your mission (should you choose to accept it) is to write a program or function that takes in two arguments:
- A string: This is the input.
- A positive integer: This the number of spaces per tab.
You must go through every line of the string and replace every tab used for indentation with the given number of spaces, and every tab not used for indentation (e.g. in the middle of a line) with one space.
Note that lines such as \t \tabc
are undefined behavior; they were inserted by the evil tab users to complicate your programs.
According to the Tabs Must Die Society, your program must be as short as possible to avoid detection by the evil tab users.
Example
\t
is used to represent tabs here.
Input string:
a
\t\tb\tc
d
Input number:
4
Output:
a
b c
d
The middle line was indented by 8 spaces, 4 per tab (since the given number was 4).
Input string:
\ta\t\tb
Input number:
4
Output:
a b
NOTE: This is not a duplicate of the tab expansion challenge; it requires a very different input format and slightly different requirements.
\ta\t\tb
,4
(my previous revision was failing that one) \$\endgroup\$