Where is documentation about String Delimiters?
Where is documentation about String Delimiters?
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
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
dCipher Computing
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Where is documentation about String Delimiters?
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.
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.
If it sounds simple, you have not grasped the complexity.
Re: Where is documentation about String Delimiters?
Hi
What I meant was:
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:
Thanks,
Simon
What I meant was:
Code: Select all
lcTxt.S = "Test" ;works okay
lcTxt.s = 'Test' ;does not work
Code: Select all
lcTxt = "It's his dog"
or
lcTxt = [It's his dog]
Simon
Simon White
dCipher Computing
dCipher Computing
Re: Where is documentation about String Delimiters?
Code: Select all
#dq = Chr(34)
string.s = "<a href="+#dq+"http://www.purebasic.fr"+#dq+">Link</a>"
Debug string
Code: Select all
string.s = esc("<a href=\qhttp://www.purebasic.fr\q>Link</a>")
Debug string
Re: Where is documentation about String Delimiters?
I understand . However, I still think this should be in the documentation especially for those coming from different programming languages.
Thanks
Thanks
Simon White
dCipher Computing
dCipher Computing
Re: Where is documentation about String Delimiters?
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:
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)
Re: Where is documentation about String Delimiters?
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
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
dCipher Computing
Re: Where is documentation about String Delimiters?
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.
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.
Re: Where is documentation about String Delimiters?
He's just asking for things to be documented, not for a change to the language.
quidquid Latine dictum sit altum videtur
Re: Where is documentation about String Delimiters?
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.'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.
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
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.
Re: Where is documentation about String Delimiters?
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
I didn't find the use of single quotes documented anywhere in the documentation
(perhaps I am only too dumb to find them
) 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 :
If this feature shouldn't be documented yet, it would be nice to add it to the help file,
because even a simple outputs
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)
(perhaps I am only too dumb to find them

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)
because even a simple
Code: Select all
Debug 'PURE'
PureBasic debugger wrote:1347768901
Re: Where is documentation about String Delimiters?
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.
)
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.
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.
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 meTomS wrote:But if you want to do it, please add also, that the following is not possible.'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.Code: Select all
Dim myArray myArray[] = 1 myArray[] = 2
Oh wait. It kinda is. pureBASIC...

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
Re: Where is documentation about String Delimiters?
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.
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.
Re: Where is documentation about String Delimiters?
Only "Hello World" isn't really usefull for an absolute beginner.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.
This kind of people needs a big tutorial.

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

MFG PMV
Re: Where is documentation about String Delimiters?
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$