How to get a doubleQuote into a string ?

Just starting out? Need help? Post your questions and find answers here.
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

How to get a doubleQuote into a string ?

Post by vmars316 »

Hello & Thanks ,
I know that the hex value is 22 ,
but I can't figure out how to get that into a string as a " .
Thanks...vm
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to get a doubleQuote into a string ?

Post by skywalk »

Code: Select all

#DQ$            = Chr(34)
MyString$ = #DQ$ + "Hello" + #DQ$
debug MyString$
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to get a doubleQuote into a string ?

Post by TI-994A »

Hello vmars316. skywalk's right; although you could also use PureBasic's built-in constant, #DQUOTE$:

Code: Select all

MyString$ = #DQUOTE$ + "Hello" + #DQUOTE$
Debug MyString$
:)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Alex777
User
User
Posts: 49
Joined: Sun Nov 16, 2008 12:47 am
Location: Cayman Is.
Contact:

Re: How to get a doubleQuote into a string ?

Post by Alex777 »

Or even #DOUBLEQUOTE$ if you prefer ...

Code: Select all

MyString$ = #DOUBLEQUOTE$ + "Hello" + #DOUBLEQUOTE$
Debug MyString$
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: How to get a doubleQuote into a string ?

Post by StarBootics »

Another way around :

Code: Select all

MyString$ = Chr(34) + "Hello" + Chr(34)
Debug MyString$
The Stone Age did not end due to a shortage of stones !
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to get a doubleQuote into a string ?

Post by TI-994A »

Or, if you prefer to use the hexadecimal values:

Code: Select all

MyString$ = Chr(Val("$22")) + "Hello" + Chr(Val("$22"))
Debug MyString$
:lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: How to get a doubleQuote into a string ?

Post by Tenaja »

TI-994A wrote:Or, if you prefer to use the hexadecimal values:

Code: Select all

MyString$ = Chr(Val("$22")) + "Hello" + Chr(Val("$22"))
Debug MyString$
:lol:
Or, better yet, just straight hex without the Val() call (which is very slow, relatively speaking)

Code: Select all

MyString$ = Chr($22) + "Hello" + Chr($22)
Debug MyString$
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to get a doubleQuote into a string ?

Post by Little John »

Another method needed? :D

Code: Select all

MyString$ = Chr('"') + "Hello" + Chr('"')
Debug MyString$
User avatar
TI-994A
Addict
Addict
Posts: 2752
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to get a doubleQuote into a string ?

Post by TI-994A »

Tenaja wrote:
TI-994A wrote:Or, if you prefer to use the hexadecimal values:

Code: Select all

MyString$ = Chr(Val("$22")) + "Hello" + Chr(Val("$22"))
Debug MyString$
:lol:
Or, better yet, just straight hex without the Val() call (which is very slow, relatively speaking)

Code: Select all

MyString$ = Chr($22) + "Hello" + Chr($22)
Debug MyString$
It was meant as a caricature to the preceding two posts. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
infratec
Always Here
Always Here
Posts: 7664
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to get a doubleQuote into a string ?

Post by infratec »

Wait until Wilbert reads this thread.
Then you'll get the fastest possible way in assembler.

:mrgreen: :mrgreen: :mrgreen:
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to get a doubleQuote into a string ?

Post by wilbert »

infratec wrote:Wait until Wilbert reads this thread.
Then you'll get the fastest possible way in assembler.

:mrgreen: :mrgreen: :mrgreen:
Sorry to disappoint you, no assembler this time :shock:
I liked the solution Little John gave with

Code: Select all

Chr('"')
If you want more workarounds, here's another one

Code: Select all

DataSection
  MyString:
  !db 'This is a test "string".', 0
EndDataSection

S.s = PeekS(?MyString, -1, #PB_Ascii)

Debug S
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
mk-soft
Always Here
Always Here
Posts: 6324
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to get a doubleQuote into a string ?

Post by mk-soft »

@wilbert
very nice :wink:

Code: Select all

t.s = "'Hallo World'"
ReplaceString(t, "'", #DQUOTE$, #PB_String_InPlace)
Debug t
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
idle
Always Here
Always Here
Posts: 6040
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: How to get a doubleQuote into a string ?

Post by idle »

wrapping it in a macro is perhaps more convenient

Code: Select all

Macro DQ(text) 
  #DQUOTE$ + text + #DQUOTE$ 
EndMacro   

mystring.s = DQ("foo") + "," + DQ("bar") 

Debug mystring
Windows 11, Manjaro, Raspberry Pi OS
Image
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: How to get a doubleQuote into a string ?

Post by vmars316 »

skywalk wrote:

Code: Select all

#DQ$            = Chr(34)
MyString$ = #DQ$ + "Hello" + #DQ$
debug MyString$
Ah, great help! Thanks..vm
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: How to get a doubleQuote into a string ?

Post by vmars316 »

TI-994A wrote:Hello vmars316. skywalk's right; although you could also use PureBasic's built-in constant, #DQUOTE$:

Code: Select all

MyString$ = #DQUOTE$ + "Hello" + #DQUOTE$
Debug MyString$
:)
Ah, good to know! Thanks..
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Post Reply