REPL-Func

 

 

NOTE - Use your Browsers BACK Button to return to prior page or CLICK here.

   REPL-Func - Replace Characters in String
Zkoala_platypus.jpg (26513 bytes) This routine replaces characters in a string with a new set... this was derived from one of the pages in my "Techniques" section (SQL alias replacement)... This function is also utilized in my SQL*Engine Utility for resolving substitution variables in script files (TDSQL)... take a look at the TDSQL source code for some ideas... also take a look at my koalas and platypus!

You can find the REPL-Func function in my custom SQR library TDFUNC.SQC

   REPL-Func - Input / Output Parameters
 
Input    - Input String
Input    - Old Character(s) - To be replaced
Input    - New Character(s) - replaces old character string
Output  - Output String (With new characters)

EXAMPLE:

let $OLD = 'where a.emplid = b.emplid'
do REPL-Func($OLD, 'emplid', 'custid', $NEW)

show 'OLD SQL string (using emplid): ' $OLD
show 'NEW SQL string (using custid): ' $NEW
     

The $NEW variable will contain:

where a.custid = b.custid

The 'emplid' value has been replaced with 'custid' on both occurances...

   Picture Archive... One of my works from 1972 (4th grade)...
arc_001.jpg (20134 bytes) My mom found some of my old pictures stored in the attic... I drew this in the 4th grade when I was 9 years old (28 years ago)... In case you're wondering it's a Tazmanian Devil... I used pastels to create this... If you click on the picture you can tell I had no idea how to use pastels properly... Hopefully some more of my past creations will appear... I'll post a few more that I have in upcoming pages...

   REPL-Func - Source Code
!**********************************************************************
!*       Replace Characters in String                                 *
!**********************************************************************
!*                                                                    *
!*        INPUT: $I_string  - Input String                            *
!*               $I_old     - Old Characters (Obsolete)               *
!*               $I_new     - New Characters (Replacement)            *
!*       OUTPUT: $O_string  - Output String (Characters Replaced)     *
!*                                                                    *
!*               To de-activate this function:                        *
!*               #define REPL_Func_Remove                             *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*      EXAMPLE: let $I_string = 'where a.emplid = b.emplid'          *
!*               do REPL-Func($I_string, 'a.', 'JOB.', $O_sql1)       *
!*               do REPL-Func($I_string, 'emplid', 'custid', $O_sql2) *
!*               do REPL-Func('A1A2A3', 'A', 'Z', $O_string)          *
!*                                                                    *
!*      RESULTS: $O_sql1   = 'where JOB.emplid = b.emplid'            *
!*               $O_sql2   = 'where a.custid = b.custid'              *
!*               $O_string = 'Z1Z2Z3'                                 *
!*                                                                    *
!**********************************************************************

#ifndef REPL_Func_Remove

begin-procedure REPL-Func($I_string, $I_old, $I_new, :$O_string)

let $O_string        = ''

let #len             = length($I_string)
let #adj             = length($I_old)
let #old             = 1
let #new             = 0

while #new           < #len

   let #new          = instr($I_string, $I_old, #old)

   if  #new          = 0
       let #new      = #len + 1
   end-if

   if  #old          < #new
       let $O_string = $O_string || substr($I_string, #old, #new - #old)
   end-if

   if  #new          < #len
       let $O_String = $O_string || $I_new
       let #old      = #new + #adj
   end-if

end-while

end-procedure

#endif

!**********************************************************************

                                                                               

   Feedback
ftoct01.jpg (12389 bytes) I would appreciate any feedback you may have on this site. Send mail to tdelia@erols.com or click on the Octopus.

   Technical difficulties?
Zanteater_sloth.jpg (32918 bytes) Please report any technical difficulties you may encounter to the address above OR click on the Octopus. Thanks.

NOTE - Use your Browsers BACK Button to return to prior page.

Tony DeLia - Updated June 03, 2000     Belugawithcalf.GIF (2387 bytes)