How to convert A00073 value to 9973 in progress 4gl

前端 未结 5 1869
日久生厌
日久生厌 2021-01-29 04:37

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..

5条回答
  •  滥情空心
    2021-01-29 05:29

    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.
    

提交回复
热议问题