efficient replace in uniface?

Author: lalitpct@gmail.com (lalitpct)


In a long piece of string i get below output , I want to replace below line with space or remove it.
I am able to use replace command but its doesnt look efficient , can anyone suggest better way of replacing.

Original string
=================
The password has expired, but you are still allowed to log in. You must change
your password before you can continue. If a login trigger is set, it will not be
executed.
Msg 9578, Level 16, State 5:
Server 'SERVERABC', Procedure 'sp_password', Line 118:
The specified password must contain at least 1 digit(s).
Msg 17720, Level 16, State 1:
Server 'SERVERABC', Procedure 'sp_password', Line 128:
Error:  Unable to set the Password.
(return status = 1)

output string (required)
====================--
Msg 9578, Level 16, State 5:
Server 'SERVERABC', Procedure 'sp_password', Line 118:
The specified password must contain at least 1 digit(s).
Msg 17720, Level 16, State 1:
Server 'SERVERABC', Procedure 'sp_password', Line 128:
Error:  Unable to set the Password.
(return status = 1)

5 Comments

  1. I guess I didnt really get your main approach, so I will ask to understand it.

    1) Do you want to cut the "output String" from the orignal string
    2) or do you want to get ONLY the output string?

    Maybe you should run through the text and separate it by a "%%^" (linefeed). I the first Chars start with "Msg " (Msg + Space), then you know that something has to be done - skip the rest or take the rest ...

     


    Author: -GHAN- (hansen@ahp-gmbh.de)
  2. I want want to get ONLY the output string


    Author: lalitpct (lalitpct@gmail.com)
  3. Then $scan(your_string,"Msg ")  and extract the stuff :)

    Copy a String from a certain point to the end SOURCE CODE
    1. lv_string = lv_string[ $scan(lv_string,"Msg ") ]

    This should copy only the rest of the String beginning with Msg (first hit) 'til the end.

     


    Author: -GHAN- (hansen@ahp-gmbh.de)
  4. Hi

    I'd further say you should get the next character, to avoid getting the leading space, or use $ltrim too:

    lv_string = $ltrim(lv_string[($scan(lv_string, "Msg "))], " ")

    or if you're sure you've only one space:

    lv_string = lv_string[($scan(lv_string, "Msg ")+1)]

    Here you also get the other way to embed a compute in string extraction, just enclose the whole with spaces. Ghan, I didn't know spaces were sufficient.

    Kind regards
    Richard


    Author: richard.gill (richard.gill@agfa.com)
  5. @Richard: Hm ... I've always used this like that. Since this is NOT HTML where white space char are commonly wiped, this thing with a trailing space should be fine :)

    btw: Did my note reach you?


    Author: -GHAN- (hansen@ahp-gmbh.de)