Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read a text and attribute it to a variable
#11
The most basic way to do this, is to write a very simple parser to do a find a replace job on the code, such as something like this:

Code: (Select All)
j$ = CHR$(34) + "QB64 Phoenix " + CHR$(34) + "+ CHR$(138) +" + CHR$(34) + " (is) beatiful" + CHR$(34)
PRINT j$

PRINT "j$ should match the format of your file perfectly above, I hope?"
PRINT
PRINT

t$ = SimpleParseCHR$(j$)
PRINT t$




FUNCTION SimpleParseCHR$ (text$)
temp$ = text$
DO
l = INSTR(temp$, CHR$(34) + "+ CHR$(")
IF l = 0 THEN EXIT DO
l1 = INSTR(l, temp$, ") +" + CHR$(34))
IF l1 = 0 THEN EXIT DO
chr = VAL(MID$(temp$, l + 8))
c$ = CHR$(chr)
temp$ = LEFT$(temp$, l - 1) + c$ + MID$(temp$, l1 + 4)
LOOP
SimpleParseCHR$ = StripQuotes(temp$)
END FUNCTION

FUNCTION StripQuotes$ (text$)
temp$ = text$
DO
l = INSTR(temp$, CHR$(34))
IF l = 0 THEN EXIT DO
temp$ = LEFT$(temp$, l - 1) + MID$(temp$, l + 1)
LOOP
StripQuotes$ = temp$
END FUNCTION


Of course, this is about as simple as possible, and only works in this one instance, but it showcases what you'd be looking for here. Note that this won't handle something such as: CHR$(34) + "Hello World" -- I'm only doing a search and replace on things with the " + CHR$(34) + " format.
Reply


Messages In This Thread
RE: Read a text and attribute it to a variable - by SMcNeill - 11-24-2023, 11:07 PM



Users browsing this thread: 3 Guest(s)