Double-quotes in strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Double-quotes in strings

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

Code: Select all

Debug "He said ""hello"" to her"
Thoughts?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Double-quotes in strings

Post by IdeasVacuum »

We all know we can use DQUOTE$
I didn't know that! :shock:
It offers consistency though, given that #CRLF$ is available too.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Double-quotes in strings

Post by c4s »

I think that's a great idea! Especially that the compiler should do this automatically.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Kiffi
Addict
Addict
Posts: 1362
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Double-quotes in strings

Post 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
Hygge
Toni6
User
User
Posts: 45
Joined: Mon Apr 23, 2012 1:39 pm

Re: Double-quotes in strings

Post by Toni6 »

+1
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Double-quotes in strings

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
deeproot
Enthusiast
Enthusiast
Posts: 271
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Double-quotes in strings

Post 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
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Double-quotes in strings

Post by skywalk »

Just shorten #DQUOTE$ to:
#DQ$ = Chr(34)
It is silly to type or read 8 characters for a " in a string. :evil:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Double-quotes in strings

Post 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. :evil:
+1 for this suggestion by skywalk.
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: Double-quotes in strings

Post by Thade »

:lol:
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? :o

Just wondering ...

RGR
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Double-quotes in strings

Post 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
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Double-quotes in strings

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Double-quotes in strings

Post by Shield »

"" makes totally sense to have and it would also be compatible to older sources whereas escape sequences wouldn't.
So +1 on "".
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Double-quotes in strings

Post by Danilo »

IdeasVacuum wrote:
We all know we can use DQUOTE$
I didn't know that! :shock:
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! :D

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.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Double-quotes in strings

Post 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).
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Post Reply