Rules for double and single quotes.

Everything else that doesn't fall into one of the other PB categories.
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Rules for double and single quotes.

Post by matthew180 »

Greetings,

Can someone give me the low-down on using quotes in PB? I cannot find any reference...

1. How do you include double quotes in a string? I've determined that the backslash '\' escape does not seem to be supported by PB...

To do this:

Code: Select all

string$ = "Quotes \"are escaped\" in other languages."
Do I have to do this?

Code: Select all

string$ = "Quotes " + chr(34) + "are escaped" + chr(34) + " in other languages."
That's a pain for sure!

2. What about single quotes? I randomly tried this:

Code: Select all

var = 'A'
debug var  --> outputs 65
This is good, as it is very C and PHP like. But, again, how do you use a single quote within a single quote?

Code: Select all

var = '\''
var = '''
Those do not work. And what about non-printable characters like newline?

Code: Select all

var = '\n'
var = '\r'
var = '\0'  <--- that's a zero
Thanks,
Matthew[/code]
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It's not basic like, how would you do the '\' then ? '\\' like in C :). I know it's a bit the pain to use Chr(34) but we will stick with it for now.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

It's certainly no problem to do this:

q.s=chr(34)
string$="Quotes "+q+"are escaped"+q+" in other languages."
Image Image
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Fred wrote:It's not basic like, how would you do the '\' then ? '\\' like in C :). I know it's a bit the pain to use Chr(34) but we will stick with it for now.
Well, pointers are not BASIC like either... :D I don't think I've ever known *any* BASIC to be just like another; they are all different in their own way, so what does BASIC like mean? Is that the same as "Unix Like"? ;-)

Why not have an escape character for strings? Do it just like in C, since that is a *very* standard way to do things. I understand that the implementation of an escape character would take some work, but not doing it because it is "not BASIC like" is not a good argument. So many other things in PB are already not BASIC like.

I've been making my living coding mostly in PHP for the last few years, and something I've reallly come to like about it is that they take the best from many languages, and combine them in PHP. For example, it does not matter if you write:

"else if" or "elseif"
<> or !=
return 0 or return(0)

and even:
"To "quote" a quote"
or
"To " . chr(34) . "quote" . chr(34) . " a quote."

It is a nice syntax because if you know any C, PERL, Java, etc. then you can already code in PHP. If you like escape characters, then you can use them, if you like to use chr(), then you can do that too. The point is that you have the option, the language does not force you to do things one way or the other. And, you won't pull your hair out trying to get something working becuase it usually works the way you tried it the first time.

I'm not bashing PB, I like the language and I want to help make it better (starting with documentation updates... hint hint... I need cvs.) I'm just pointing out that having an open attitude towards the way things are done, and doing things in more than one way, makes a language much nicer and easier to use! People will instantly feel comfortable with PB and start using it for everything!

I'll get off my soapbox now. :-)

Matthew
Post Reply