This article show a couple of procedures used to Search and Replace into a Uniface field/variable. All the information has been extracted from the news-groups.

Has anyone come across the need for a Search & Replace function in a string variable/field, similar to the Replace function in VB6 ?

  1. By Marty.Trujillo@mail.imds.org
  2. entry lpm_

    params

    string pio_source : inout

    string pi_repchar : in

    string pi_newchar : in

    endparams

    repeat

    scan pio_source, pi_repchar

    if ($result = 0) break

    $1 = $result - 1

    $2 = $result + 1

    pio_source = "%%pio_source[1,$1]%%pi_newchar%%pio_source[$2]"

    until(0)

    return 0

    end; lpm

    I usually use this to replace <gold> semicolons ( ; ) with <gold> ors ( | ), but

    pi_repchar and pi_newchar could be anything strings you want.

     

  3. By franklin_nurmohamed@virginia-it-services.nl

There is some functionality in Uniface:

To find a 'HG' in $1 = "ABCHGDBHG" You use:

scan $1,"HG"

The result is in $result.

You can use :

$3 = $result -1

$4 = $result + 2

$2 = "%%$1[1,$3]%%%REPLACEMENT%%$1[$4]%%%"

The string in $2 is now "ABCREPLACEMENTDBHG"

(The use of global variables $1..$99 can be replaced by local variables since Uniface 7 but I used it here to makes things more clear)

Regards and have fun,

Franklin M Nurmohamed

Senior Uniface Designer

SVA Virginia IT Services, The Netherlands

http://www.virginia-it-services.nl

mailto:franklin_nurmohamed@virginia-it-services.nl

  1. By tony@marston-home.demon.co.uk]

The way to do this is with a global proc. Here is a copy of the one I created earlier this year:

 

; Name: EXAMINE_REPLACE

; Author: Tony Marston

; Date: 20-06-99

; Current Version: 1.0.0

; Description: Examine STRING replacing all occurrences of old_text with new_text

; Input Parameters: STRING - string containing old_text ; p_old_text - to be replaced with new_text

; p_new_text - replacement for old_text

; Output Parameters: STRING

; examine STRING replacing "X" with "Y"

params

string p_string_in : INOUT

string p_old_text : IN

string p_new_text : IN

endparams

variables

string lv_input_area, lv_hold, lv_output_area

numeric lv_old_text_len

endvariables

lv_input_area = p_string_in ; move to work area

length p_old_text

lv_old_text_len = $result ; store length of old text

while (lv_input_area != "") ; repeat until empty

scan lv_input_area, p_old_text ; look for old_text

if ($result < 1) ; not found

lv_hold = lv_input_area ; use whole string

lv_input_area = "" ; nothing left

else ; found

$result = $result -1 ; backspace over old text

lv_hold = lv_input_area[1:$result] ; extract pre-old text

lv_hold = "%%lv_hold%%p_new_text" ; append new text

$result = $result + lv_old_text_len ; add length of old text

$result = $result +1 ; skip over old text

lv_input_area = lv_input_area[$result] ; drop pre-old text

endif

lv_output_area = "%%lv_output_area%%lv_hold"

endwhile

p_string_in = lv_output_area ; replace with adjusted string

return(0)

Hope this helps.

--

Tony Marston

[mailto:tony@marston-home.demon.co.uk]

[mailto:TonyMarston@hotmail.com]