这是我的问题
define varibale MyArray as character extent 40 no-undo.
define variable Mychara as character no-undo.
Mychara = "hai this is checking how to copy values"
现在我想将此字符串复制到我的“MyArray”。所以它应该如下
MyArray [1] = h,MyArray [2] = a,MyArray [3] = i,MyArray [4] =“”,MyArray [5] = t,MyArray [6] = h 等等...
那怎么办?
答案 0 :(得分:5)
鉴于您的代码示例,这应该可以解决问题:
define variable MyArr as character EXTENT 40 no-undo.
define variable Mychara as character no-undo.
Mychara = "hai this is checking how to copy values".
DEF VAR i AS INT NO-UNDO.
DO i = 1 TO 40:
MyArr[i] = SUBSTRING(MyChara,i,1).
END.
但需要注意的是:这意味着您必须事先知道String的(最大)大小,以便适当地定义数组大小。
答案 1 :(得分:2)
动态一点点;)
define variable MyArr as character EXTENT no-undo.
define variable Mychara as character no-undo.
DEF VAR i AS INT NO-UNDO.
Mychara = "hai this is checking how to copy values".
EXTENT (MyArr) = LENGTH (Mychara).
DO i = 1 TO EXTENT (MyArr):
MyArr[i] = SUBSTRING(MyChara,i,1).
END.
答案 2 :(得分:1)
define var l_mychara as integer no-undo.
define variable MyArray as character format "x(5)" extent 40 no-undo.
define variable Mychara as character format "x(5)" no-undo.
def var i as int init 1.
Mychara = "hai this is checking how to copy values".
assign l_mychara = length(Mychara).
do while i <= l_mychara.
assign myarray[i] = substring(mychara,i,1).
if myarray[i] = "" then assign myarray[i] = "blank".
i = i + 1.
end.
disp Myarray .