trim

Q&A's, tips, howto's
Locked
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

trim

Post 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Neat and Elegant! :)

Eddie

Locked