Where is documentation about String Delimiters?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
swhite
Enthusiast
Enthusiast
Posts: 790
Joined: Thu May 21, 2009 6:56 pm

Where is documentation about String Delimiters?

Post by swhite »

Hi

I have been looking in the documentation for the rules about string delimiters. Is there more than one string delimiter? I know I can test out my ideas but it would be nice to have some definitive answer in the documentation on string delimiters under "General Rules".

Simon
Simon White
dCipher Computing
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Where is documentation about String Delimiters?

Post by IdeasVacuum »

Hi Simon

Not sure what you mean - there are no rules except file etiquette (e.g. CSV file values should be separated by commas). The delimiter used is entirely up to the creator of the file and if you so wished you could of course save a CSV delimited by tabs, periods, anything (not that you would be popular for doing so).

There is also no rule that says a delimiter must be a single character, I am working with files where the delimiter is '//' between x,y,z vals.

PB's StringField() is designed to support single-character delimiters only:

http://www.purebasic.com/documentation/ ... field.html

So, if reading from a file, your code needs to work-out what delimiter has been used, or ask the User in a similar way that Word for example converts text to a table.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
swhite
Enthusiast
Enthusiast
Posts: 790
Joined: Thu May 21, 2009 6:56 pm

Re: Where is documentation about String Delimiters?

Post by swhite »

Hi

What I meant was:

Code: Select all

lcTxt.S = "Test" ;works okay

lcTxt.s = 'Test' ;does not work

So I can use double quotes but not single quotes. How would I include quotes in the string? This is especially common in creating HTML code dynamically where javascript is included. In some languages I can do:

Code: Select all

lcTxt = "It's his dog"

or

lcTxt = [It's his dog]


Thanks,
Simon
Simon White
dCipher Computing
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Where is documentation about String Delimiters?

Post by TomS »

Code: Select all

#dq = Chr(34)
string.s = "<a href="+#dq+"http://www.purebasic.fr"+#dq+">Link</a>"
Debug string
EDIT: Another methode would be using escape sequences. Here are some procedures that allow escaped strings. http://purebasic.fr/german/viewtopic.php?p=137326

Code: Select all

string.s = esc("<a href=\qhttp://www.purebasic.fr\q>Link</a>")
Debug string
swhite
Enthusiast
Enthusiast
Posts: 790
Joined: Thu May 21, 2009 6:56 pm

Re: Where is documentation about String Delimiters?

Post by swhite »

I understand . However, I still think this should be in the documentation especially for those coming from different programming languages.

Thanks
Simon White
dCipher Computing
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Where is documentation about String Delimiters?

Post by TomS »

Why?
If you want a language that's like php or C++ then learn a language that's like them.
You don't need a list of features of C++ in the PB-Documentation just to show that PB doesnn't have them or that they are implemented another way.

Another solution for the HTML-problem:

Code: Select all

Procedure.s sq2dq(string.s, flag = 1)
	Select flag
		Case 2
			ProcedureReturn ReplaceString(string,"''",Chr(34))
		Default 
			ProcedureReturn ReplaceString(string,"'",Chr(34))
	EndSelect 
EndProcedure 

string.s = "<a href='http://www.purebasic.fr'>Link</a>"
Debug sq2dq(string)

string.s = "<a href=''http://www.purebasic.fr''>Link</a>"
Debug sq2dq(string,2)
swhite
Enthusiast
Enthusiast
Posts: 790
Joined: Thu May 21, 2009 6:56 pm

Re: Where is documentation about String Delimiters?

Post by swhite »

Hi

I am happy with PB and do not need to learn another language nor am I asking that PB become like another language. All I am asking is that PB's string delimiters be documented. There is nothing that I could find that clearly states PB only uses double quotes and not single quotes.

Thanks,
Simon
Simon White
dCipher Computing
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Where is documentation about String Delimiters?

Post by TomS »

Every example in the help uses double quotes.
Adding the note that single quotes can't be used for strings (as they are used for binary data eg. '10010101') would exactly be what I mentioned before. Just because it is possible in other languages, doesn't mean it's possible in PB. There's probably not a single basic language out there that uses single quotes for strings. After all that's what PB is. A Basic dialect.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Where is documentation about String Delimiters?

Post by freak »

He's just asking for things to be documented, not for a change to the language.
quidquid Latine dictum sit altum videtur
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Where is documentation about String Delimiters?

Post by TomS »

Is my english that bad, or is it yours, freak? Nobody said something about changes to PB.
He's asking for something to be documented that's NOT possible with PB but is with other languages.
I asked "why"?
But if you want to do it, please add also, that the following is not possible.

Code: Select all

Dim myArray
myArray[] = 1
myArray[] = 2
'Cause it sucks coming from other languages like php, which allow that kind of stuff. And there's nowhere in the entire helpfile written that it's not allowed.
Oh wait. It kinda is. pureBASIC...

The documentation should be about what is possible with PB. And not about what is not possible.
If you read the help and look at the examples, why would you even think that single quotes could be used with strings?
And if you try it and the debugger shows you an error message, why would one open a thread about it?
The documentation may not be perfect, but how about a bit of thinking?

There were two choices.
a) There simply is no other way to create a string, because this is Basic and not Java
b) Single quotes don't work, [ doesn't work, maybe there's an undocumented limiter like #-+String+-#, I will ask in the forum about it.

And shwite chose the latter and got an answer, that a) would have been right.
Either he's happy now, or things that don't work in PB but in other languages will be included in the helpfile.
But mind you, there's a lot that doesn't work just the way it does in other languages. Because they're not PB and PB is not them.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Where is documentation about String Delimiters?

Post by Shardik »

There exists one exception to the rule that strings cannot be enclosed in single
quotes. For MacOS API calls often a TagName (a string consisting of 4 characters,
which are handled as a 4 byte long integer value) is used to get or set special
features of a control (Gadget).

Fred and freak posted MacOS examples using API calls like

Code: Select all

Result = GetControlProperty(GadgetID(0), 'PURE', 'TXOB', 4, 0, @TXNObject)
I didn't find the use of single quotes documented anywhere in the documentation
(perhaps I am only too dumb to find them :wink:) and I tried several hours to use the
more familiar @"PURE" instead (which didn't work). The single quotes seem to cause
the PB compiler to convert the string into the long integer value because you can
replace the above tag 'PURE' by :

Code: Select all

Tag = Asc("P") << 24 + Asc("U") << 16 + Asc("R") << 8 + Asc("E")
Result = GetControlProperty(GadgetID(0), Tag, 'TXOB', 4, 0, @TXNObject)
If this feature shouldn't be documented yet, it would be nice to add it to the help file,
because even a simple

Code: Select all

Debug 'PURE'
outputs
PureBasic debugger wrote:1347768901
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Where is documentation about String Delimiters?

Post by freak »

He wants the way it is done in PB to be documented. Not how it is different from other languages.

In fact, there is no section in the manual describing the notation of literal values (numbers, strings) in PB and which formats are accepted. This belongs to the basic definition of a language and should be included. You can't expect people to extrapolate this information from code examples spread around the documentation.

Single quotes do have a defined purpose in PB: They denote a numerical constant with the ascii value of one or more characters. Did you know that? Did you find that out by looking at examples? I am sure it is used somewhere, but it is not documented in a place where people can find it.
TomS wrote:But if you want to do it, please add also, that the following is not possible.

Code: Select all

Dim myArray
myArray[] = 1
myArray[] = 2
'Cause it sucks coming from other languages like php, which allow that kind of stuff. And there's nowhere in the entire helpfile written that it's not allowed.
Oh wait. It kinda is. pureBASIC...
The help file defines how arrays work in PB. The point is that it doesn't do the same for strings. (which is a pretty BASIC omission if you ask me ;))

As creators and long time users of a language, we tend to overlook it if such basic details are missing. But they are important and they should be in the manual.
quidquid Latine dictum sit altum videtur
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Where is documentation about String Delimiters?

Post by TomS »

Oh yeah. I muddled that up. Single quotes are not for binary, but an Asc() equivalent that takes whole strings as Shardik pointed out.
And yes. That's documented. Asc() <- F1
But only a single char. It's documented that it can take a string.

@Freak: Yeah. You're right. But there is so much stuff beginners don't know. That pro's see as basic stuff. Where do you draw the line.
For an absolute beginner, the helpfile is completely useless, if you look at it that way. There's not even a hello world example.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Where is documentation about String Delimiters?

Post by PMV »

TomS wrote:For an absolute beginner, the helpfile is completely useless, if you look at it that way. There's not even a hello world example.
Only "Hello World" isn't really usefull for an absolute beginner.
This kind of people needs a big tutorial. :wink:

btw.:
http://en.wikibooks.org/wiki/Computer_P ... #PureBasic
http://de.wikipedia.org/wiki/Liste_von_ ... #PureBasic
... :lol:

MFG PMV
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Re: Where is documentation about String Delimiters?

Post by Baldrick »

Just for interests sake & its lack of documentation

Code: Select all

y=8
Dim z.b(y)
;*z=@z() ; if u want...
z(0)='P'
z(1)='U'
z(2)='R'
z(3)='E'
z(4)='B'
z(5)='A'
z(6)='S'
z(7)='I'
z(8)='C'
For a=0 To y 
;c$=PeekS(*z+a,1)
c$=PeekS(@z()+a,1)
b$+c$
  Debug c$ 
Next 
Debug "**********************"
Debug b$
Post Reply