Page 1 of 1

trim

Posted: Mon Jun 14, 2004 1:54 pm
by 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.

Posted: Mon Jun 14, 2004 8:45 pm
by Lutz
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

Posted: Mon Jun 14, 2004 9:01 pm
by eddier
Neat and Elegant! :)

Eddie