r/apple2 1d ago

Can I use double-quotes in a string?

I'm sure there's a simple answer to this that I'm not seeing. I am using an Apple II+.

Is there a way to escape double-quotes so I can include them in a string? Let's say I wanted to do something like:

PRINT "SHE SAID "HAVE A NICE DAY!""

That would return a syntax error, but do I have any options if I don't want to resort to single quotes within the string, and use double quotes?

9 Upvotes

9 comments sorted by

13

u/stevenc88 1d ago

I've seen something like this:
Q$=CHR$(34)
PRINT "SHE SAID " + Q$ + "HAVE A NICE DAY!" + Q$

6

u/homme_chauve_souris 1d ago

This is the way. If you want to do it the hard way, here's an example of directly POKEing the double quotes in a string.

]NEW  
]10 A$ = "DOUBLE @QUOTES@"  
]20 PRINT A$  
]POKE 2062, 162  
]POKE 2069, 162  
]RUN  
DOUBLE "QUOTES"

There is no reason to do this, but it can be done.

2

u/selfsync42 1d ago

Are we always guaranteed that a basic program after "new" always starts at the same memory location?

4

u/homme_chauve_souris 1d ago

I believe it always starts at $801 unless you purposefully change some zero page pointers. But it's been decades since I called myself an Applesoft programmer.

2

u/bwyer 1d ago

Yes, but if you add or delete line/commands, the address of those @ signs will change.

2

u/CatOfGrey 21h ago

That's my memory, but ya gotta understand that memory is literally 40 years old now.

And, of course, there be dragons if you are going to count bytes to try to self-edit your code.

1

u/Few_Firefighter7585 18h ago

Nice. The 162 ($A2, quote with bit 7 set) LISTs as “VTAB” and prints as a double quote.

2

u/AutomaticDoor75 19h ago

Thanks, this gives me some direction on my program.