12-15-2022, 01:48 AM
(This post was last modified: 12-15-2022, 01:55 AM by mnrvovrfc.
Edit Reason: All those double-quotes are making me dizzy
)
(12-14-2022, 10:44 PM)Kernelpanic Wrote: The CHR$(34) function stands for the Ascii character >"<. If I now replace CHR$(34) with the relevant character, the error message below appears - see screenshot.
Is it correct that CHR$(34) is only intended to prevent >"< from being criticized as already existing?
We would need a way to "escape" a character which is difficult to rein in. Freebasic could do it with CHR$(34), but QB64(PE) cannot. It's historical. Part of the frustration is unable to do this:
Code: (Select All)
CONST qu = CHR$(34)
This whether or not the "variable" carries a dollar sign.
In Freebasic the alternative method is to treat the whole string as in C, using the backslash to "protect" the character that comes right after it, including another backslash, and including low-ASCII codes like the null and newline. This is done by beginning the whole entry with an exclamation point like:
Code: (Select All)
PRINT !"\"D:\\Program Files\\notepad++\\notepad++.exe\" tmp.three"
EDIT: Could also do like Pascal and put two double-quotation marks where one is wanted, but it's strange to read.
https://www.freebasic.net/wiki/ProPgLiterals
(section "String Literals")
EDIT 2: One way to resolve it in QB64(PE) is to write a function called "Quoth$" or alike which replaces a chosen weird character with the CHR$(34). Or wraps the entire string value passed as parameter with CHR$(34). Something like this:
Code: (Select All)
PRINT Quoth$("D:\Program Files\notepad++\notepad++.exe") + " tmp.three"
FUNCTION Quoth$ (astr$)
Quoth$ = CHR$(34) + astr$ + CHR$(34)
END FUNCTION