Given text, remove leading and trailing whitespace (spaces, tabs, and newlines).
Alternate title: Implement your own string trimming.
Input
ASCII text (printable + spaces, tabs (\t
), and newlines (\n
)), in whatever format you would like. Carriage returns (\r
) are outside of the scope of the input.
Output
The same text in the same format, but with (only) trailing and leading spaces, tabs, and newlines removed.
*Note: If your language naturally outputs a trailing space/newline, please note that in your answer.
Test Cases
This test case ensures that you can handle \s
and the like. Please note whitespace in it.
Input
\s test \t\n
Output
\s test \t\n
For the following test cases (but not the above), \s
is space, \t
is tab, \n
is newline. =>
splits input and output.
\s\t\n\s => (empty string)
\stest\s => test
\nt\n\st\t => t\n\st
_ => _
\s\s\n\s1\s+\s1\n => 1\s+\s1
||_\s => ||_
No builitins allowed that trim either specific characters or given characters. Builtins that remove arbitrary characters from the beginning/end of a string, or that remove given characters from any position in a string (by default) are allowed.
s[1:]
trimming? \$\endgroup\$