Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!brutus.cs.uiuc.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!mis.mcw.edu!tenaglia From: tenaglia@mis.mcw.edu (Chris Tenaglia - 257-8765) Newsgroups: comp.lang.icon Subject: Handy Icon Procedure for Reports Message-ID: <9003142249.AA22806@uwm.edu> Date: 14 Mar 90 20:05:15 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 49 Dear Icon Group : I am including a handy procedure that can reformat strings. It's fairly intuitive as far as usage is concerned. My implementaion is pretty plain. Perhaps someone has a more elegant expression that makes use of string scanning or co-expressions? Enjoy! ######################################################################## # # # THIS PROCEDURE IS A HANDY STRING REMAPPER/FORMATTER AND IT'S # # VERY HANDY FOR REPORT GENERATION. USAGE PATCH(VARIABLE,MASK) # # WHERE VARIABLE IS A STRING AND MASK IS A STRING. MASK CONTAINS # # A SEQUENCE THAT TRANSFORMS VARIABLE. THE # CHARACTER MEANS TO # # COPY THE CHARACTER AT THAT POSITION. THE $ CHARACTER MEANS TO # # DELETE THE CURRENT CHARACTER AT THAT POSITION. ANY OTHER BYTES # # GET INSERTED INTO THE VARIABLE AT THEIR RESPECTIVE POSITIONS. # # EXAMPLES : patch("12/03/89","##$##$##") returns 120389 # # patch("120389","##/##/19##") returns 12/03/1989 # # patch("12/03/1989","##$") returns 12 # # # ######################################################################## procedure patch(var,mask) text := "" i := 0 every mark := !mask do { case mark of { "#" : { text ||:= var[(i+:=1)] next } "$" : { i +:= 1 next } default : text ||:= mark } } return text end ############################################################# Chris Tenaglia (System Manager) Medical College of Wisconsin 8701 W. Watertown Plank Rd. Milwaukee, WI 53226 (414)257-8765 tenaglia@mis.mcw.edu