如何将A00073值转换为9973正在进行4gl

问题描述 投票:0回答:5

我的列有多个值,如A0045,A00065。我想将其转换为9945,9965。需要删除所有0和字符值并在该值之前添加99 ..请帮助..

openedge progress-4gl 4gl
5个回答
0
投票

这可以通过多种方式完成。这是一种方式(可能不是最好的)。因为我没有数据库,所以我创建了一个临时表。

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.

0
投票

下面的代码也删除了大写字母(A-Z)和小写字母(a-z)以及“0”:

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.

0
投票

将变量单词定义为字符no-undo。

将变量i定义为整数no-undo。

分配word =“A00065”。

/ *******删除所有零******** /

word = replace(word,substring(word,index(word,“0”),(r-index(word,“0”) - 1)),“”)。

我i = 65到90:如果substring(word,1,1)= chr(i)那么:

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

结束。

结束。

显示单词。


0
投票
  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.

0
投票

如果这对您有用,请告诉我,Progress未安装,因此无法编译和测试。

/ * 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.
© www.soinside.com 2019 - 2024. All rights reserved.