Page 1 of 1

Quotes escape character for strings

Posted: Thu Oct 27, 2011 7:49 pm
by Senacharim
Hi!
I've searched the forum & help file, but I'm not finding the answer on this one.

Is there an escape character which can be used for including a " in a string?

Normally it's \, but that's not working.

Any help or advice appreciated,
Thanx in advance.

Posted: Fri Oct 28, 2011 7:55 am
by David Barker
There are a number of ways you can do this

Code: Select all

include "usart.bas"
setbaudrate(br19200)
write("hello ",34,"world",34)
write(13,10)
or

Code: Select all

include "usart.bas"
dim myString as string
myString = "Hello " + #34 + "World" + #34
setbaudrate(br19200)
write(myString,13,10)
The first code example is far more efficient in terms of MCU resources than the second example.

Posted: Fri Oct 28, 2011 4:36 pm
by Senacharim
Could one do something like:

Code: Select all

Dim TehString as String
TehString = 34, "Hello World", 34
??

Wait, it occurs to me I can test this myself... let's see...
[time passes]
Ah, so, no the above does not work,

Code: Select all

TehString = char(34) + "Hello World!" + Char(34)
also does not work.

Alright, so after piddling with it,

Code: Select all

TehString = char(34) + "Hello World!" + Char(34)
MY_LCD.Write(TehString)
does not work, but

Code: Select all

TehString = "Hello World!"
MY_LCD.Write(Char(34))
MY_LCD.Write(TehString)
MY_LCD.Write(Char(34))
DOES work.

Odd.

Oh well.

Thanks.

Posted: Sat Oct 29, 2011 1:21 pm
by Jerry Messina
I can see why some of the syntax posted wouldn't work, but I just happened to try

Code: Select all

dim s as string

s = char(34) + "ABC"                    // works... s = DB 0X22, 0X41, 0X42, 0X43, 0X00
s = "ABC" + char(34)                    // works... s = DB 0X41, 0X42, 0X43, 0X22, 0X00
s = char(34) + "ABC" + char(34)         // DOESN'T work... s = DB 0X41, 0X42, 0X43, 0X00
s = #34 + "ABC" + #34                   // DOESN'T work... same as previous
s = "AB" + char(34) + "CD" + char(34)   // works... s = DB 0X41, 0X42, 0X22, 0X43, 0X44, 0X22, 0X00
Looks like there's something funny with the third case, and the compiler doesn't like it.

Posted: Sun Oct 30, 2011 12:01 pm
by David Barker
I'll add it to my to do list ;-)