Appending text

Hi,

Is it possible to append a text to another text in Natural.

Suppose,

#A=“ABC”
I want the numbers 1 to 9 also to be alongwith the variable #A.

I will be doin the appending of the numbers in a loop each number separated by a comma.

I want the result to be “ABC,1,2,3,4,5,6,7,8,9”

Folks,

I got the answer myself…It is as follows,

MOVE “ABC” to #TXTA

FOR #I 1 TO 9
COMPRESS #TXTA #I INTO #TXTA WITH ALL DELIMITERS ‘,’
END-FOR

Thanks,

I hope you are not intending to put this code into production anywhere.

Instead of your code, try:

MOVE ‘ABC,1,2,3,4,5,6,7,8,9’ TO #TXTA

Assuming that the numbers you want to add are not really 1…9 but numbers in an array, try:

COMPRESS #TXTA #ARRAY (*) INTO #TXTA WITH DELIMITER ‘,’

You might want (as you had above), ALL DELIMITERS, if #ARRAY is alpha. Then a blank entry in #ARRAY would produce something like 1,2,4 etc

This would not happen if #ARRAY was numeric. COMPRESS with a zero value would result in a string such as 1,2,0,4 etc

Finally, two points. First, using the FOR loop as you showed above is about as inefficient a way to do this as exists in Natural (okay, i guess if you really tried you could do something like):

            FOR #I = 1 to 9
            COMPRESS #TXTA #I INTO #TXTA LEAVING NO SPACE
            COMPRESS #TXTA ',' INTO #TXTA LEAVING NO SPACE
            END-FOR

Next, please get a Natural class and do not try to learn Natural by yourself. You will end up writing horrible code.

steve