Reputation: 582
this is my issue
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"
Now i want to copy this string to my "MyArray". So that it should be as follows
MyArray[1]=h ,MyArray[2]=a ,MyArray[3]=i ,MyArray[4]="" ,MyArray[5]=t ,MyArray[6]=h and so on...
So how to do it?
Upvotes: 2
Views: 7837
Reputation: 548
Given your code-example, this should do the trick:
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.
A caveat though: this means that you have to know the (maximum) size of your String beforehand, to define the array size appropriately.
Upvotes: 7
Reputation: 11
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 .
Upvotes: 1
Reputation: 254
little bit dynamically ;)
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.
Upvotes: 2