[TF] mylib.tf : updated chr2chr()
Brought to you by:
kenkeys
|
From: tinyfugue at attbi.c. (Galvin) - 2003-04-30 23:21:03
|
I made the code more tigher, it works slightly faster than the old chr2chr()
;==============================================================================
; chr2chr()
;
; Changes one character to difference character in a string
; USAGE:
; x := chr2chr("string", "searchchar", "changechar")
;
; x : contains "string" with all "." as "_".
; "string" : any string.
; "searchar" : The character to be changed in "string".
; "changechar : The character to replace each occrance of "searchar" in
; "string".
;==============================================================================
/def chr2chr = \
/let right_ 0 %;\
/test right_ := {1} %;\
/let searchchar_ 0 %;\
/test searchchar_ := {2} %;\
/let changechar_ 0 %;\
/test changechar_ := {3} %;\
/let left_= %;\
/let pos_ -1 %;\
/WHILE ( (pos_ := strstr(right_, searchchar_)) > -1) \
/test left_ := strcat(left_, substr(right_, 0, pos_), changechar_) %;\
/test right_ := substr(right_, pos_ + 1) %;\
/DONE %;\
/RETURN strcat(left_, right_)
|