[TF] mylib.tf patch: strip_left() and strip_right()
Brought to you by:
kenkeys
|
From: tinyfugue at attbi.c. (Galvin) - 2003-04-27 08:11:02
|
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)
;==============================================================================
; strip_left()
;
; Strips all leading spaces from a string.
; USAGE:
; x := strip_space("string")
;
; x : Returned "string" with no leading spaces.
; "string" : Any string
;==============================================================================
/def strip_left = \
/let st_ 0 %;\
/test st_ := {1} %;\
/let count_ -1 %;\
/let len_ $[strlen(st_)] %;\
/WHILE ( (++count_ < len_) & (substr(st_, count_, 1) =~ ' ') ) \
/DONE %;\
/return substr(st_, count_)
|