CONCAT statement

Purpose:

CONCAT will append one string to another.

Syntax:

CONCAT(Str1 AS STRING, Str2 AS STRING)

Parameters:

  • Data type: STRING
    Str1 String to which Str2 is appended.
  • Data type: STRING
    Str2 String to append to Str1

Remarks:

Str1 must be sized large enough to hold the combined size of Str1 and Str2.

Example:

DIM Str1$ * 60000
DIM Str2$
DIM Start!
DIM Elapsed!

Start! = ROUND((float)clock()/(float)CLOCKS_PER_SEC,2)
FOR INTEGER i = 1 TO 10000
   Str2$ = STR$(i)
   Str1$ = Str1$ & Str2$
NEXT i
Elapsed! = ROUND((float)clock()/(float)CLOCKS_PER_SEC,2)
PRINT ""
PRINT "Using Str1$ = Str1$ & Str2$ ", Elapsed! - Start!, " seconds"

Str1$ = ""

Start! = ROUND((float)clock()/(float)CLOCKS_PER_SEC,2)
FOR INTEGER i = 1 TO 10000
   Str2$ = STR$(i)
   CONCAT(Str1$,Str2$)
NEXT i
Elapsed! = ROUND((float)clock()/(float)CLOCKS_PER_SEC,2)
PRINT ""
PRINT "Using CONCAT ", Elapsed! - Start!, " seconds"

Result:

Using Str1$ = Str1$ & Str2$  0.07 seconds

Using CONCAT  0.07 seconds

+= string concat operator

Purpose:

A shorthand form of String1 = String1 + OtherString.

Syntax:

StringVar += Arglist

Parameters:

  • None

Example:

DIM AS STRING StringVar
StringVar = "Oh Boy, "
StringVar += "it worked!"
PRINT StringVar

Result:

Oh Boy, it worked!

$FILL directive

Purpose:

The $FILL directive, appends the list of string expressions to the supplied string variable.

The $FILL directive was added to BCX to provide the MyStr$ += [string expresssion] functionality available in other programming languages.

$FILL tolerates blank lines and lines that start with REM and the comment symbol (') You may use $FILL in any context where MyStr$ = MyStr$ + [string expression] would be valid, in both LOCAL and GLOBAL contexts of your programs.

Syntax:

$FILL SomeValidStringVariableName
[STRING expresssion]
[STRING expresssion]
[STRING expresssion]
$FILL

Example 1:

$BCXVERSION "7.5.9"

DIM A$

$FILL A$
"Permission is hereby granted, free of charge, to any person obtaining "
"a copy of this software and associated documentation files (the 'Software'),"
"to deal in the Software without restriction, including without limitation "
"the rights to use, copy, modify, merge, publish, distribute, sublicense, "
"and/or sell copies of the Software, and to permit persons to whom the "
"Software is furnished to do so, subject to the following conditions: "

'---------------------------- 
Rem This is a comment
'---------------------------- 

CRLF$ + CRLF$ + UCASE$("blah blah blah ") + CRLF$
"and more blah blah blah " + CRLF$
UCASE$( "still more blah blah blah ...")
$FILL

MSGBOX A$

Result:

This is an image produced by the above code.

Example 2:

$BCXVERSION "7.5.9"

DIM MyStr$

$FILL MyStr$
"this is test # 1" + CRLF$
"this is test # 1" + CRLF$
"this is test # 1" + CRLF$
$FILL

PRINT MyStr$


DIM A[10,10,10] AS STRING

$FILL A [5,5,5]
"this is test # 2" + CRLF$
"this is test # 2" + CRLF$

'---------------------------- 
REM This is a comment
'---------------------------- 

"this is test # 2" + CRLF$
"this is test # 2" + CRLF$
$FILL

PRINT A$ [5,5,5]


TYPE BCXFOO
  DIM SomeWords [500] AS CHAR
END TYPE


DIM Sample AS BCXFOO


$FILL Sample.SomeWords
"this is test # 3" + CRLF$
"this is test # 3" + CRLF$
"this is test # 3" + CRLF$
$FILL


PRINT Sample.SomeWords$

PAUSE

Result:

this is test # 1
this is test # 1
this is test # 1

this is test # 2
this is test # 2
this is test # 2
this is test # 2

this is test # 3
this is test # 3
this is test # 3


Press any key to continue . . .

Remarks:

👉 Starting with BCX 777, the variable being $FILLed is first cleared. The original behavior required clearing the variable explicitly, such as:

MyVar$ = ""
$FILL MyVar$
...
...
$FILL

$FILL simply performs a "search and replace" at translation time when it encounters its usage.

$FILL has been tested with simple strings ( MyStr$ ), multi-dimensional arrays ( MyStr$[x,x,x] ) and with string members of TYPE structures ( Addressbook.FirstName$ )