Page 1 of 2

How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 2:50 am
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

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 2:53 am
by skywalk

Code: Select all

#DQ$            = Chr(34)
MyString$ = #DQ$ + "Hello" + #DQ$
debug MyString$

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 4:43 am
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$
:)

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 3:20 pm
by Alex777
Or even #DOUBLEQUOTE$ if you prefer ...

Code: Select all

MyString$ = #DOUBLEQUOTE$ + "Hello" + #DOUBLEQUOTE$
Debug MyString$

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 3:36 pm
by StarBootics
Another way around :

Code: Select all

MyString$ = Chr(34) + "Hello" + Chr(34)
Debug MyString$

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 3:40 pm
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:

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 4:37 pm
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$

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 5:46 pm
by Little John
Another method needed? :D

Code: Select all

MyString$ = Chr('"') + "Hello" + Chr('"')
Debug MyString$

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 6:20 pm
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:

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 6:30 pm
by infratec
Wait until Wilbert reads this thread.
Then you'll get the fastest possible way in assembler.

:mrgreen: :mrgreen: :mrgreen:

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 6:38 pm
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

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 10:13 pm
by mk-soft
@wilbert
very nice :wink:

Code: Select all

t.s = "'Hallo World'"
ReplaceString(t, "'", #DQUOTE$, #PB_String_InPlace)
Debug t

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:02 pm
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

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:43 pm
by vmars316
skywalk wrote:

Code: Select all

#DQ$            = Chr(34)
MyString$ = #DQ$ + "Hello" + #DQ$
debug MyString$
Ah, great help! Thanks..vm

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:44 pm
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..