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

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Andy

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

Post 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
Andy

A solution (the only one?)

Post 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
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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 ..
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Code: Select all

WRITE "Hello there!"
I have left this dump.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Ah Z!re's right it works! Hmmm....now I must go and experiment with write.... :D
"But...It was so beutifully done"
Andy

Post by Andy »

Thanks for your help. Those leading zeros are history! :)

Andy
Post Reply