Quotes in strings without typing Chr(34) or #DQUOTE$

Share your advanced PureBasic knowledge/code with the community.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Quotes in strings without typing Chr(34) or #DQUOTE$

Post by Dude »

I just realized embedding inline quotes is possible by using \" and the escape string operator (~). Great stuff! :)

Code: Select all

a$=~"He said \"hello\" to his friends"
Debug a$
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Quotes in strings without typing Chr(34) or #DQUOTE$

Post by Lunasole »

Dude wrote:I just realized embedding inline quotes is possible by using \" and the escape string operator (~)
"in less than 2 years" ^^

Yes, that's one of nice things added to language recently, before I typically used ' instead of " and then ReplaceString()
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Quotes in strings without typing Chr(34) or #DQUOTE$

Post by Dude »

Lunasole wrote:"in less than 2 years"
Yes, it was added 9 months ago. But the manual doesn't explain much about it, except that escape characters are supported. I had no idea \" was an escape character. :)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Quotes in strings without typing Chr(34) or #DQUOTE$

Post by Kwai chang caine »

Always good to know
Thanks 8)
ImageThe happiness is a road...
Not a destination
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Quotes in strings without typing Chr(34) or #DQUOTE$

Post by Keya »

another day another new PB trick to add to the toolbelt! :) and i had a look in the hex editor - the string is saved in escaped format (eg. \"Hi\" is saved in the exe as "Hi" not \"Hi\") , so no extra code is generated either (i guess that makes it a preprocessor thing?), nice and efficient in true Purebasic style :)
Post Reply