[TF] mylib.tf patch: strip_left() and strip_right()
Brought to you by:
kenkeys
|
From: nieten at math.uni-bonn.de (M. Nieten) - 2003-04-28 16:36:20
|
On Sun, 27 Apr 2003, Galvin wrote:
> Ok i'm too confused calling this stuff strip_trail, or strip_lead, so I
> renamed the original function and made another as well.
> That's it for striping of spaces.
> ;==============================================================================
> ; strip_right()
> ;
> ; Strips all trailing spaces from a string.
> ; USAGE:
> ; x := strip_right("string")
> ;
> ; x : Returned "string" with no leading spaces.
> ; "string" : Any string
> ;==============================================================================
> /def strip_right = \
> /let st_ 0 %;\
> /test st_ := {1} %;\
> /let count_ $[strlen(st_)] %;\
> /WHILE ( (--count_ > 0) & (substr(st_, count_, 1) =~ ' ') ) \
> /DONE %;\
> /return substr(st_, 0, count_ + 1)
The shorter (and probably more efficient) version is
/def strip_right = /result "$(/echo %*)"
(I don't how how escape sequences would be treated by this macro,
but on pure ascii strings it works fine.)
Regards,
Martin
|