Posts: 1,058
Threads: 367
Joined: Oct 2007
I need to concatenate a character at the end of each one of the elements of an lpstr string. In the first place it works. However, when I try to access the elements of the string I always get, to every element, the value of the last element. I attach the code I use. Any advice regarding my error will be much appreciated. Many thanks in advance.
Function
tempf07
ARRAY(lpstr) af
str s="a|b|c"
tok s af -1 "|" 1
for int'i 0 af.len
,af[i]=F"{af[i]}*"
,out af[i]
for i 0 af.len
,out af[i]
Posts: 12,071
Threads: 140
Joined: Dec 2002
F"string" creates a hidden local str variable to store the formatted string. Each loop uses the same variable and therefore overwrites it. F"strings" in other places use other hidden variables.
rep n
,s=F"string{x}"
is the same as
rep n
,str _hiddenLocalVariable1.format("string%i" x); s=hiddenLocalVariable1
In your case, all the lpstr strings are stored in s (the str variable). af[0] is s, af[1] is s+2, af[1] is s+4. Cannot concatenate. Use ARRAY(str), and then af[i]+"*".
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras, Many thanks for very useful advice.