Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concatenate a character at the end of an lpstr string
#1
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
Code:
Copy      Help
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]
#2
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]+"*".
#3
Dear Gintaras, Many thanks for very useful advice.


Forum Jump:


Users browsing this thread: 1 Guest(s)