1

这是我的问题

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 ,M​​yArray[3]=i ,MyArray[4]="" ,MyArray[5]=t ,MyArray[6]=h 等等...

那么该怎么做呢?

4

3 回答 3

6

鉴于您的代码示例,这应该可以解决问题:

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 的(最大)大小,才能适当地定义数组大小。

于 2012-03-28T07:47:51.427 回答
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.
于 2012-04-13T22:27:56.960 回答
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 .
于 2012-07-23T09:51:48.223 回答