48
2
We already now how to strip a string from its spaces.
However, as proper gentlemen/ladies, we should rather undress it.
Undressing a string is the same as stripping it, only more delicate. Instead of removing all leading and trailing spaces at once, we remove them one by one. We also alternate between leading and trailing, so as not to burn steps.
Example, starting with " codegolf "
(five leading and trailing spaces):
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
codegolf
First output the string unchanged. Then, output every step. Begin by removing a leading space (if applicable - see rule #2).
The input may have a different number of leading and trailing spaces. If you run out of spaces on one side, keep undressing the other until the string is bare.
The input may have no leading nor trailing spaces. If that's the case, output it as-is.
Use PPCG's default I/O methods. PPCG Default loopholes are forbidden.
Undefined behaviour on empty input, or input that only contains spaces, is OK.
You can assume that the string will only contain characters from the ASCII printable space (
0x20
to0x7E
).
Examples - spaces are replaced by dots .
for better readability:
4 leading spaces, 5 trailing: "....Yes, Sir!....."
....Yes, Sir!.....
...Yes, Sir!.....
...Yes, Sir!....
..Yes, Sir!....
..Yes, Sir!...
.Yes, Sir!...
.Yes, Sir!..
Yes, Sir!..
Yes, Sir!.
Yes, Sir!
6 leading, 3 trailing: "......Let's go golfing..."
......Let's go golfing...
.....Let's go golfing...
.....Let's go golfing..
....Let's go golfing..
....Let's go golfing.
...Let's go golfing.
...Let's go golfing
..Let's go golfing
.Let's go golfing
Let's go golfing
0 leading, 2 trailing: "Hello.."
Hello..
Hello.
Hello
0 leading, 0 trailing: "World"
World
21 leading, 5 trailing: ".....................a....."
.....................a.....
....................a.....
....................a....
...................a....
...................a...
..................a...
..................a..
.................a..
.................a.
................a.
................a
...............a
..............a
.............a
............a
...........a
..........a
.........a
........a
.......a
......a
.....a
....a
...a
..a
.a
a
A gentleman/lady is concise, so the shortest answer in bytes wins.
From Sandbox: https://codegolf.meta.stackexchange.com/a/13765/71426
– Nathan.Eilisha Shiraini – 2017-09-21T09:19:15.097Can we assume that there will be at least one non-space character? – Martin Ender – 2017-09-21T09:34:23.883
@MartinEnder Yes – Nathan.Eilisha Shiraini – 2017-09-21T10:23:31.623
Can a test string contain new-lines or tabs? (Or more precisely, will the spaces have the lowest decimal value
32
in the strings?) – Kevin Cruijssen – 2017-09-21T10:47:10.6832@KevinCruijssen You only have to handle ASCII characters in the printable space (
0x20
to0x7E
). The other ones are Undefined Behavior. – Nathan.Eilisha Shiraini – 2017-09-21T10:54:26.537@Nathan.EilishaShiraini Ok, so a test case like
" \ntest "
or" \t test "
isn't possible (\n
being a line-feed;\t
being a tab)? – Kevin Cruijssen – 2017-09-21T10:55:46.1201@KevinCruijssen Yes, there will be no test case like this. There will be no things like
" test\r "
or" \v test"
either. – Nathan.Eilisha Shiraini – 2017-09-21T10:57:16.653@Nathan.EilishaShiraini LOL! Thank you for this idea :) – frarugi87 – 2017-09-21T12:12:37.893
do we need to output as 1 line for each step or can we return a list of strings with all the steps? – Felipe Nardi Batista – 2017-09-21T12:52:40.523
1Is this a valid test case
".....................a....."
? If so I suggest to add it since some answers seems to fail this kind of test. (dots are for better readability of course) – Cinaski – 2017-09-21T13:54:27.267@FelipeNardiBatista I thought list of string instead of multiline string was implicitely allowed as part of the standard I/O methods. Now: it is explicitely valid. – Nathan.Eilisha Shiraini – 2017-09-21T14:48:18.697
Added @Cinaski 's suggested test case. Thanks! – Nathan.Eilisha Shiraini – 2017-09-21T14:59:25.137
After testing the answers with Cinaski's test case, I found that some of them inconsistently add a trailing empty line. Since they are already there, and upvoted, I will allow this in order to leave these answers valid. – Nathan.Eilisha Shiraini – 2017-09-21T15:20:25.880
Somehow the terminology feels backwards to me. In my mind, undressing is something that happens relatively quickly, usually done by yourself, whereas stripping is often about making it take as long as possible to turn it into a proper show. – Trejkaz – 2017-09-25T05:23:29.333