Page 1 of 1

How to WRITE or PRINT a string containing quotes to a file?

Posted: Sat Apr 02, 2005 12:28 pm
by Andy
Hello,

I'm not a programmer, but like to dabble in QuickBasic, and am currently stumped!

I'd like to write a string of data to a sequential (readable, ASCII)
file that contains quotes in it. Specifically, I am assembling an MS-DOS
batch statement from QB:

PRINT #1, "if "%1"=="bypass" goto end"

Of course, the second quote PRINT sees is interpreted as the end of the string.

Can I get around this?

Thanks a bunch,
Andy

A solution (the only one?)

Posted: Sat Apr 02, 2005 2:36 pm
by Andy
Sorry for the double-post, but I realize I can write a " to the file by using
CHR$(034). The line becomes :

PRINT #1, "if " + CHR$(034) + "%1" + CHR$(034) + "==" + CHR$(034) + "bypass" + CHR$(034) + " goto end"

Is this the only / best way?

Andy

Posted: Sat Apr 02, 2005 4:58 pm
by Rattrapmax6
Saddly yes, ( " ) these are string commands in QB so you have to put the escape code CHR$(034) for it,.. but um, you can leave out the "0" and just put CHR$(34).. :wink: .. that would be a easier way in a way :D ..

Posted: Sun Apr 03, 2005 5:11 am
by Z!re

Code: Select all

WRITE "Hello there!"

Posted: Sun Apr 03, 2005 10:14 am
by Mitth'raw'nuruodo
Ah Z!re's right it works! Hmmm....now I must go and experiment with write.... :D

Posted: Sun Apr 03, 2005 4:11 pm
by Andy
Thanks for your help. Those leading zeros are history! :)

Andy