trim

Started by eddier, June 14, 2004, 06:54:55 AM

Previous topic - Next topic

eddier

Lutz,



(trim currently works on both sides of a string. It would be nice if it could sometimes be restricted to the left side or right side of a string.



Example



(trim "00239800" "0" LEFT) => "239800"



or



(trim "00239800" "0" RIGHT) => "002398"



The LEFT and RIGHT constants are probably not the best way. It might be better having two

trim functions: (ltrim and (rtrim ?



Currently, I'm using (nth 3 (regex {0*(d+)} w)) for the left trim.



Eddie.

Lutz

#1
This is how the new trim in 8.0.8 will work:



(trim "   hello  ") => "hello"



(trim "----hello----" "-") => "hello"



(trim "0001234" "0" "") => "1234"



(trim "1234000" "" "0") => "1234"



(trim "----hello====" "-" "=") => "hello"



a second syntax can specify a left and a right trim character, an empty string trims nothing.



Lutz

eddier

#2
Neat and Elegant! :)



Eddie