Author Topic: += for strings  (Read 376 times)

jcfuller

  • Sr. Member
  • ****
  • Posts: 268
    • View Profile
+= for strings
« on: October 09, 2020, 07:36:05 AM »
Kevin,

Would it be possible to have a "+=" For strings?
Buffer$ += "New Item"
James

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 714
    • View Profile
Re: += for strings
« Reply #1 on: October 09, 2020, 08:45:43 AM »
I've seen it used in PB and FB and have tinkered with adding it to BCX in the past.

The trick is coming up with an elegant algorithm for integrating it.

It's been a while -- maybe I'll revisit the subject.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 714
    • View Profile
Re: += for strings
« Reply #2 on: October 09, 2020, 10:57:52 AM »
I decided to lead instead of follow.

I created a new directive named $FILL, modeled after $COMMENT.
It accomplishes the same thing as:  MyStr$ +=
but with  a lot less redundant typing and (importanly) no risk of breaking BCX.

* It accepts any valid string argument
* It tolerates BLANK LINES
* It tolerates lines that start with the comment character  (') and REM

SAMPLE:

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$
« Last Edit: October 09, 2020, 11:29:08 AM by MrBcx »

jcfuller

  • Sr. Member
  • ****
  • Posts: 268
    • View Profile
Re: += for strings
« Reply #3 on: October 10, 2020, 04:17:05 AM »
Good Stuff.
  Can't wait to try it.

James

JoeC4281

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: += for strings
« Reply #4 on: October 10, 2020, 11:59:18 AM »
This is similar to the "Here-document" trickery (https://jpsoft.com/forums/threads/here-document-trickery.4068/#post-23010) that is used in Take Command Console.

Nice to be able to do a similar task now in BCX.

Joe

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 714
    • View Profile
Re: += for strings
« Reply #5 on: October 11, 2020, 10:34:42 AM »
Here is another sample that will likely make its way into the BCX Help File.

Code: [Select]

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