Quotes escape character for strings

Discuss the Integrated Development Environment (IDE)

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Quotes escape character for strings

Post by Senacharim » Thu Oct 27, 2011 7:49 pm

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.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Oct 28, 2011 7:55 am

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.

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Fri Oct 28, 2011 4:36 pm

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.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sat Oct 29, 2011 1:21 pm

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.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Sun Oct 30, 2011 12:01 pm

I'll add it to my to do list ;-)

Post Reply