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
#12
Very good!
Thank you all for your kind cooperation and help!

After the disappointment for RhoSigma's words, I was just weighing on a system like the one proposed by SMcNeill, which then - as I saw - preceded me in the realization.

And it works!

Obviously, it needs to be adapted a bit to my code and to the cases that may arise, but that is the solution to the problem.
Reply




Users browsing this thread: 2 Guest(s)