0

次のような変数を分割するInformix 4glコマンドを知りたかった

lv_var = variable01;variable02

の中へ

lv_var01 = variable01
lv_var02 = variable02

Informix 4gl でこれを実行できるものはありますか。

Pythonで私ができること

lv_array = lv_var.split(";")

配列の変数を使用します

4

3 に答える 3

1

このようなものを備えた従来の Informix 4gl では可能です...

define
    p_list      dynamic array of char(10)

main
    define
        i       smallint,
        cnt     smallint,
        p_str   char(500)

    let p_str = "a;b;c;d"
    let cnt = toarray(p_str, ";")

    for i = 1 to cnt
        display p_list[i]
    end for

end main

function toarray(p_str, p_sep)
    define
        p_str   char(2000),
        p_sep   char(1),
        i       smallint,
        last    smallint,
        ix      smallint,
        p_len   smallint

    let ix = 0
    let p_len = length(p_str)

    # -- get size of array needed
    for i = 1 to p_len
        if p_str[i] = p_sep then
            let ix = ix + 1
        end if
    end for

    if ix > 0 then
        # -- we have more then one
        allocate array p_list[ix + 1]

        let ix = 1
        let last = 1
        for i = 1 to p_len
            if p_str[i] = p_sep then
                let p_list[ix] = p_str[last,i-1]
                let ix = ix + 1
                let last = i + 1
            end if
        end for
        # -- set the last one
        let p_list[ix] = p_str[last, p_len]
    else
        # -- only has one
        allocate array p_list[1]
        let ix = 1
        let p_list[ix] = p_str
    end if

    return ix

end function

外:

a
b
c
d

動的配列のサポートには、IBM Informix 4GL 7.32.UC1 以降が必要です

于 2016-09-22T21:47:29.070 に答える