How to convert A00073 value to 9973 in progress 4g

2019-03-06 06:02发布

问题:

i have column having multiple value like A0045 ,A00065 . i want to convert it 9945, 9965. Need to remove all 0 and character value and add 99 before that value.. Please help..

回答1:

This can be done in many ways. Here is one way (may not be the best). As I don't have a database, I created a temp table.

def temp-table tt 
    field val as char.

create tt.
tt.val = "A0045".

create tt.
tt.val = "A00065".

for each tt:
    run filter_zero(input-output val).
    val = replace(val,"A","99").
    DISP val.
end.

procedure filter_zero:
    define input-output parameter val  as character.

    // remvoe all zeroes 
    repeat while val matches("*0*"): 
        val = replace(val,"0","").
    end.

end procedure.


回答2:

The code below removes the uppercase (A-Z) and lowercase letter (a-z) and "0" as well :

DEF TEMP-TABLE test
    FIELD str1 AS CHAR.

DEF VAR newStr AS CHAR NO-UNDO.
DEF VAR i AS INT NO-UNDO.

CREATE test.
ASSIGN test.str1 = "A0045".

CREATE test.
ASSIGN test.str1 = "A00065".

FOR EACH test:
    DO i = 65 TO 90: /* A - Z */
        IF SUBSTR(test.str1, 1, 1) EQ CHR(i) THEN
        DO:
            test.str1 = REPLACE(test.str1, CHR(i), "").       
        END.
    END.

    DO i = 97 TO 122: /* a - z */
        IF SUBSTR(test.str1, 1, 1) EQ CHR(i) THEN
        DO:
            test.str1 = REPLACE(test.str1, CHR(i), "").       
        END.
    END.

    /* Removes all 0 and add 99 before the value */
    test.str1 = REPLACE(test.str1, "0", "").
    ASSIGN test.str1 = "99" + test.str1.
    DISP test.
END.


回答3:

define variable word as character no-undo.

define variable i as integer no-undo.

assign word = "A00065".

/*******To Remove all the zero********/

word = replace(word,substring(word,index(word,"0"),(r-index(word,"0") - 1)),"").

do i = 65 to 90: if substring(word,1,1) = chr(i) then do:

  word = replace(word,substring(word,1,1),"99").
  leave.

end.

end.

display word.



回答4:

  DEFINE VARIABLE word AS CHARACTER   NO-UNDO.
    SET word.
    word =  REPLACE(word,SUBSTRING(word,1,R-INDEX(word,"0")),"99").   
    /* If you want to remove all words before last zero 
     (including last zero also)  * /

    MESSAGE word
        VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.


回答5:

Please do let me know if this works for you, Progress not installed so couldn't compile and test.

/* A0045 -> 9945 A00065 -> 9965 */

DEFINE VARIABLE v_RawData AS CHARACTER NO-UNDO.
DEFINE VARIABLE v_InpData AS CHARACTER NO-UNDO.
DEFINE VARIABLE i         AS INTEGER NO-UNDO.
DEFINE VARIABLE j         AS INTEGER NO-UNDO.

ASSIGN v_RawData = "A0045,A00065".

DO i =1 TO NUM-ENTRIES(v_RawData):
    ASSIGN v_InpData = ENTRY(i,v_RawData).

    DO j = 1 TO LENGTH(v_InpData):
        IF ASC(SUBSTRING(v_InpData,j,1)) > 48 AND 
           ASC(SUBSTRING(v_InpData,j,1)) < 58 THEN
            DO:
                LEAVE.
            END.
    END.
    MESSAGE REPLACE(v_InpData,SUBSTRING(v_InpData,1,j - 1),"99").
END.