FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

TEXT

Mix two regular strings into a long string


You can also BLOCKMOVE characters (up to 255 of them) in the long string to and from regular strings if it's easier to deal with them there. Here is some code (untested) that will combine two FB strings into a long string, or split a long string into 2 FB strings, in case you want to print them or do other operations that are easier with regular strings.

LOCAL FN longStr2TwoStrs(myLongStr)
  DIM myFBStr$,myOtherFBStr$,lenLong
  lenLong = PEEK WORD(@myLongStr)
  LONG IF lenLong < 511
    LONG IF lenLong > 255
      BLOCKMOVE @myLongStr + 2, @myFBStr$ + 1, 255
      POKE @myFBStr$, 255
'now myFBStr$ holds first 255 chars
      BLOCKMOVE @myLongStr + 257, @myOtherFBStr$ +1,lenLong - 255
      POKE @myOtherFBStr$, lenLong - 255
'myOtherFBStr$ holds any remaining chars
    XELSE 'Only needs one string
      myFBStr$ = PSTR$(@myLongStr + 1)
      POKE @myOtherFBStr$, 0
    END IF
'Do whatever with the strings
  XELSE 'Won't fit in two strings
    BEEP:PRINT "This string is too long to split."
  END IF
END FN

LOCAL FN twoStrs2longStr(str1$,str2$)
  DIM myLongStr.362
  BLOCKMOVE @str1$ + 1, @myFBStr$ +2, LEN(str1$)
  BLOCKMOVE @str2$ + 1, @myFBStr$ +2 + LEN(str1$), LEN(str2$)
  % @myLongStr, LEN(str1$) + LEN(str2$)
'Do whatever with the long string
END FN

Jay