Page 1 of 1

Big Problem with string concatenation - it's nonexistent

Posted: Sat Dec 31, 2011 4:24 am
by Tdarcos
Consider the following piece of code:

Code: Select all

routine DMFB
{
local describe, describe2

   print "Original values "; 
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   Describe  = "One"
   Describe2 = "Two"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   Describe = Describe + describe2
   print "Final result:"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   print "Sample ends."
You get the following result when this routine is called:

Original values describe = '' describe2 = ''
describe = 'One' describe2 = 'Two'
Final result:
describe = '' describe2 = 'Two'
Sample ends.

Clearly, the compiler doesn't support concatenations. Typical practice is the + sign for this purpose; the manual doesn't even contain the word "catenate" or mention any capability to combine two strings. At least I know this now so I can work around it.

Posted: Sat Dec 31, 2011 7:05 am
by Roody_Yogurt
Nope, you're right, that isn't possible. You can "add" strings, though, by using the "text to" and "dict" commands.

Code: Select all

! add this first line to the beginning of the source file
$MAXDICTEXTEND = 7
! sets aside some space so we can add more words to the dictionary table after compilation

array describearray[7] ! a seven element array can hold six letters

routine DMFB
{
local describe, describe2

   print "Original values: ";
   print " describe = '"; describe;"' describe2 = '"; describe2;"'"
   Describe  = "One"
   Describe2 = "Two"
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
	text to describearray
	print Describe;
	print describe2;
	text to 0
	Describe = dict(describearray, 7)
 
   print "Final result: ";
   print " describe = '"; describe;"' describe2 = '"; describe2;"' "
   print "Sample ends." 
}

Also, you wouldn't have to use dict if you weren't actually setting the describe variable to the combined string. You could just fake it, of course:

Code: Select all

!...
	text to 0
   print "Final result: ";
   print " describe = '"; StringPrint(describearray);"' describe2 = '"; describe2;"' "
!...