Page 1 of 4
Double-quotes in strings
Posted: Mon Mar 04, 2013 2:10 pm
by MachineCode
I think this may have been requested before, but not sure. We all know we can use DQUOTE$ to include a double-quote in our strings, but I think it'd be handy that when the compiler sees 2 x ' in a string, it converts them to a DQUOTE$ automatically. In everyday language you don't use 2 x ' at all, so it's freely available to exploit. Like this:
Code: Select all
Debug "He said ''hello'' to her" ; Outputs -> He said "hello" to her
Instead of the uglier:
Code: Select all
Debug "He said "+#DQUOTE$+"hello"+#DQUOTE$+" to her"
Visual Basic allows this sort of thing, except it does it like this:
Thoughts?
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 2:15 pm
by IdeasVacuum
We all know we can use DQUOTE$
I didn't know that!
It offers consistency though, given that #CRLF$ is available too.
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 2:29 pm
by c4s
I think that's a great idea! Especially that the compiler should do this automatically.
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 3:46 pm
by Kiffi
MachineCode wrote:In everyday language you don't use 2 x ' at all
-1
the following queries would fail:
Code: Select all
DatabaseUpdate(myDb, "Update myTable Set myField = '' Where myID = 123")
DatabaseQuery(myDb, "Select * From myTable Where myField <> ''")
Greetings ... Kiffi
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 4:18 pm
by Toni6
+1
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 4:31 pm
by helpy
MachineCode wrote:... but I think it'd be handy that when the compiler sees 2 x ' in a string, it converts them to a DQUOTE$ automatically. In everyday language you don't use 2 x ' at all.
-1
I do not like this idea!
I would prefer the Visual Basic style!
I also would use Escape sequences like in C using the back slash!
cu,
guido
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 4:49 pm
by deeproot
Kiffi wrote:the following queries would fail:
Code: Select all
DatabaseUpdate(myDb, "Update myTable Set myField = '' Where myID = 123")
DatabaseQuery(myDb, "Select * From myTable Where myField <> ''")
Yes that would be a big problem, plus in SQlite and others 2 x ' are used as an escape to embed a single quote in a query - it's in
the SQLite FAQ.
So also -1
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 5:39 pm
by skywalk
Just shorten #DQUOTE$ to:
#DQ$ = Chr(34)
It is silly to type or read 8 characters for a " in a string.

Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 5:49 pm
by Little John
skywalk wrote:Just shorten #DQUOTE$ to:
#DQ$ = Chr(34)
It is silly to type or read 8 characters for a " in a string.

+1 for this suggestion by skywalk.
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 5:58 pm
by Thade
There are many useless "Feature Requests" lately - especially from people which are not really long time users of PB ...
Hey. Why don't you just write some Apps and Games instead of thinking about what you personally don't like in PB. Why do you want to destroy long time users work base?
I believe most of us are happy since 10 years with the language as it is ... we get great updates ... Fred adds really USEFUL features step by step ... and the language has developed great ...
So what is the reason that lately so many rather new to PB people want to change the Language and want to add all sorts of booze ideas ?
For the thing above I use +CHR(34)+ since 30 years now (or +dq+ if its needed more often) ... its BASIC ... in all those years I never would have got such a booze idea to make double quotes a thing that has to be specially featured ... and to add to Kiffi's example ... you change something on one end and initialize a rat tail of trouble on the other ...
If you have the option settings right you have the best IDE to work with, compared to 100s of other languages ... you can program with only some keystrokes, rather everything is autofilled and predicted ... in other languages you'd have to write a novel to achieve the same. What makes some of you so unsatisfied?
Just wondering ...
RGR
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 6:05 pm
by Danilo
MachineCode wrote:Thoughts?
Code: Select all
Macro DQ : +#DOUBLEQUOTE$+ : EndMacro
Debug "He said "DQ"hello"DQ" to her" ; Outputs -> He said "hello" to her
UndefineMacro DQ
;-----------------------------
Macro DQ(s) : #DQUOTE$ + s + #DQUOTE$ : EndMacro
Debug "He said "+DQ("hello")+" to her" ; Outputs -> He said "hello" to her
;-----------------------------
#DQ$ = #DQUOTE$ ; agree, could be shortened in PB resident
Debug "He said "+#DQ$+"hello"+#DQ$+" to her" ; Outputs -> He said "hello" to her
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 6:37 pm
by Tenaja
Thade wrote:There are many useless "Feature Requests" lately - especially from people which are not really long time users of PB ...
...So what is the reason that lately so many rather new to PB people want to change the Language and want to add all sorts of booze ideas ?
The reason is that most people come to PB, NOT as a "new to programming" user, but as a programmer experienced in another language. As such, there are many features that one may miss from their previous language, and wish for it in PB.
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 7:01 pm
by Shield
"" makes totally sense to have and it would also be compatible to older sources whereas escape sequences wouldn't.
So +1 on "".
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 7:12 pm
by Danilo
IdeasVacuum wrote:We all know we can use DQUOTE$
I didn't know that!

I added this constants to PB, round about 9 or 10 years ago. It is my fault I didn't add the short #DQ$ too. Sorry skywalk for being so stupid!
Full list is available in FAQ section in german forum:
(PB) Nützliche Konstanten... die niemand kennt ("Useful constants... who nobody knows")
In my opinion PB should not replace anything within my strings automatically. So using the double quote character itself (like VB)
would be the only valid option, because it is the only printable character that can't be used in strings directly.
helpy wrote:I also would use Escape sequences like in C using the back slash!
file$ = "C:\\program files\\myprog\\file.ext" ?
Not PB, but solution for something like this is available somewhere in Tips & Tricks.
Re: Double-quotes in strings
Posted: Mon Mar 04, 2013 11:13 pm
by MachineCode
I didn't realise it would ruin database queries, so I guess it's not such a good idea after all.

Oh well, that's why I asked for thoughts. I've always hated (with any Basic) how you have to break up a string like Chr(34) like that, just to use quotes. At least VB solved the problem in a semi-acceptable way (ie. it still looks ugly in VB).