newLISP Fan Club

Forum => newLISP in the real world => Topic started by: eddier on June 14, 2004, 06:54:55 AM

Title: trim
Post by: eddier on June 14, 2004, 06:54:55 AM
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.
Title:
Post by: Lutz on June 14, 2004, 01:45:15 PM
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
Title:
Post by: eddier on June 14, 2004, 02:01:08 PM
Neat and Elegant! :)



Eddie