How do I trim leading and trailing whitespace in Common Lisp?
How do I trim leading and trailing whitespace in Common Lisp?
Asked Answered
CL-USER> (string-trim
'(#\Space #\Newline #\Backspace #\Tab
#\Linefeed #\Page #\Return #\Rubout)
" A string ")
"A string"
string-left-trim
and string-right-trim
for leading and trailing whitespace, respectively.
The second argument to string-trim is a character bag which can be a sequence. You might consider using a vector instead of a a list for better access. Additionally, are you sure that you got all the whitespace characters? Many implementations will include functions along the lines of whitespace-char-p. It might be worthwhile to iterate through character codes and collect all the characters satisfying it ahead of time, and use that as the sequence of white space characters. –
Plight
© 2022 - 2024 — McMap. All rights reserved.
string-trim
, and the second hit is the HyperSpec entry tostring-trim
. It's not clear, to me anyway, that this question needs answering on SO. – Plight