Uniface User Forum

 View Only
Expand all | Collapse all

Uniface 8: using replace one in tricky way

  Thread closed by the administrator, not accepting new replies.
  • 1.  Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    using replace one in tricky way

    Author: lalitpct@gmail.com (lalitpct)


    In a variable below is the content and I want to remove the path shown for a file , and I would like to do in uniface

    ***00-RETURN: Listing Files:
    -rwxrwxr-x    1 smt2uxb  smt2uxb       28561 May 12 2010  /opt/uat/eur/sources/sqr/ftp_make.sqr:1
    -rwxrwxr-x    1 smt2uxb  smt2uxb       28560 May 13 2010  /opt/uat/eur/sources/sqr/ftp_make.sqr

    what I was thinking was
    1)find first position " /" via scan command
    2)Find end of the word found from above position
    3)from the end to the left find /
    4)Replace the above string from first " /" to the end "/" in the variable
    5)loop until all of them are replaced

    the second step I am unable to think of anyway to do it , please let me know if any one has got any idea to do  or if they have done this before.
    If you have better idea on this you can tell me that as well



  • 2.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    Hi, maybe something like this can help you,

    vspath="/opt/uat/eur/sources/sqr/file"
    vsexit="N"
    while (vsexit="N")
        vspath=$replace(vspath,1,$syntax("/&*/"),"/",-1)
        if($scan(vspath,"/")=$rscan(vspath,"/"))
            vsexit="Y"
            vspath=vspath[2]
        endif
    endwhile
     

    Regards, Rafa.


    Author: uniface8 (spanish_uniface@hotmail.es)


  • 3.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    Hi

    Thanks for reply it seems $replace is a better way of achieveing my goal , thanks for pointing to that

    however it gives output as 

    -rwxrwxr-x    1 smt2uxb  smt2uxb       28561 May 12 2010   uat a c c c/ftp_make.sqr:1

     $syntax("/&*/")   how does it work ? I mean if  we can trac patter like /opt/uat/eur/a/b/c/c/c/c/c/  ( /*/) then it will be done in one single command  

    text_to_view="-rwxrwxr-x    1 smt2uxb  smt2uxb       28561 May 12 2010  /opt/uat/eur/a/b/c/c/c/c/c/ftp_make.sqr:1"
    text_to_view=$replace(text_to_view,1,$syntax("/&*/")," ", -1)


    Author: lalitpct (lalitpct@gmail.com)


  • 4.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    That pattern finds /any character/ , if you do
    $replace(text_to_view,1,$syntax("/&*/")," ", -1)

    you replace /opt/   uat  /eur/  a   /b/   c   /c/   c   /c/   c/ --> uat a c c c/ftp_make.sqr

    look at the example;
    while (..)
        $replace(text_to_view,1,$syntax("/&*/"),"/", -1)
    endwhile

    at the end of the first loop you get
    /opt/uat/eur/a/b/c/c/c/c/c/ftp_make.sqr -->/uat/a/c/c/c/ftp_make.sqr
    in the second
    /uat/a/c/c/c/ftp_make.sqr-->/a/c/ftp_make.sqr
    the third
    /a/c/ftp_make.sqr-->/c/ftp_make.sqr
    and finally
    /c/ftp_make.sqr-->/ftp_make.sqr

    Modify the instruction to end the while cause in 8.4 rscan not exist.

    Regards, Rafa.


    Author: uniface8 (spanish_uniface@hotmail.es)


  • 5.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    thanks it worked ,


    Author: lalitpct (lalitpct@gmail.com)


  • 6.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    always running scan througl a long text results in unacceptable performance.

    So at first separate the file so you work always with a single line.
     

    if you use the current uniface version, there is a "scan from right side" $rscan to speed up processing.

    Using an external file gives you the alternative to apply regular-expression replacement (outside of uniface)
    and just load the resulting file.

    Uli

    P.S: If it is an external file you can use USEQREAD to read it line-by-line with lightspeed processing.
    AND you reduce memory consumption from "the whole filesize" down to "the longest line"


    Author: ulrich-merkel (ulrichmerkel@web.de)


  • 7.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    uniface version is 8.4 and hence it seems rscan is not working


    Author: lalitpct (lalitpct@gmail.com)


  • 8.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    ... and 8.4 is NOT the current version I mentioned


    Author: ulrich-merkel (ulrichmerkel@web.de)


  • 9.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    From my personal archives: a "rightscan avant la lettre", which will work in Uniface version 8 and below:

     

    entry RIGHTSCAN
    params
       string  pi_string   : IN
       string  pi_profile  : IN
       numeric po_position : OUT
    endparams
    variables
       numeric lv_len_profile
       string  lv_characters
    endvariables

    length pi_profile
    lv_len_profile = $result

    length pi_string
    po_position   = $result - lv_len_profile + 1
    lv_characters = pi_string[po_position:lv_len_profile]
    while(lv_characters != pi_profile & po_position > 0)
       po_position   = po_position - 1
       lv_characters = pi_string[po_position:lv_len_profile]
    endwhile
    end
     

    Usage example:
    call RIGHTSCAN(u_glab.ucrelsh, "_", lv_positie)
     


    Author: Arjen van Vliet (arjen.van.vliet@uniface.com)


  • 10.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.


    uniface version is 8.4 and hence it seems rscan is not working


    So it would have been better if you posted this in the Uniface 8 part of the forum...


    Author: Theo Neeskens (tneeskens@itblockz.nl)


  • 11.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    i have moved it to 8.4


    Author: lalitpct (lalitpct@gmail.com)


  • 12.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    because uniface is terrible slow handling longer texts and does not provide enough string manipulation routines I recommend external processing.

    Using GAWK.EXE (open source awk for windows) a simple command line (use a SPAWN or activate OSCOMMAND) will do the job:

    C:\#mig_awk>gawk " {sub(/\/.*\//,'',$0);print}" < lalitpct.in
    ***00-RETURN: Listing Files:
    -rwxrwxr-x    1 smt2uxb  smt2uxb       28561 May 12 2010  ftp_make.sqr:1
    -rwxrwxr-x    1 smt2uxb  smt2uxb       28560 May 13 2010  ftp_make.sqr
     

    it's fast, straight foreward so why spend time and energy in doing it otherwise.

    And if you got the info from a unix system, why not ask if someone can "pipe" this awk command into the preparation sequence ?

    Uli


    Author: ulrich-merkel (ulrichmerkel@web.de)


  • 13.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    Hello

     

    i dont remember in what version uniface introduce the $itemcount , $itemnr but if these commands are available to your version you can simply translate your string in list and get the last element from list

    vsFileName = "-rwxrwxr-x    1 smt2uxb  smt2uxb       28560 May 13 2010  /opt/uat/eur/sources/sqr/ftp_make.sqr"

    ;The ; is the golden ;
    vsFullPath = $ItemNr($ItemCount($Replace(vsFullPath,1,"/","·;",-1)),$Replace(vsFullPath,1,"/","·;",-1))

    ;Result Is :
    ; vsFullPath = "ftp_make.sqr"


    Author: jtsagara (jtsagara@logisoft.gr)


  • 14.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    Without $itemcount it is possibile to use

    vsFullPath = $ItemNr(-1,$Replace(vsFullPath,1,"/","·;",-1))

    to extract the last element from the list.

     


    Author: Marco (marco.aquino@dedalus.eu)


  • 15.  RE: Uniface 8: using replace one in tricky way

    ROCKETEER
    Posted 11-19-2018 11:47
    No replies, thread closed.

    Yes marco

     

    this is possible after some patching ( if i remember well ) in uniface

    cause in first edititions of uniface that can handle $itemnr ( i think ~ 8 or 9 ) had a bug with -1

     

    cheers

     


    Author: jtsagara (jtsagara@logisoft.gr)