#CRLF$ as StringField delimiter

Just starting out? Need help? Post your questions and find answers here.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: #CRLF$ as StringField delimiter

Post by Demivec »

MachineCode wrote:I see in the manual that StringField's delimiter can only be one character. But, this works with #CRLF$. Why?

Code: Select all

Debug Len(#CRLF$) ; Returns 2

a$="123"+#CRLF$+"456"+#CRLF$+"789"

For i=1 To CountString(a$,#CRLF$)+1
  Debug StringField(a$,i,#CRLF$)
Next
The example only appears to work. StringField() only pays attention to the first character of the string it is given.

To illustrate this, lengthen the string it is given with characters that aren't in the string being examined and compare the results with the example you gave.

Code: Select all

Debug Len(#crlf$) ; Returns 2

a$="123"+#crlf$+"456"+#crlf$+"789"

For i=1 To CountString(a$,#crlf$)+1
  Debug StringField(a$,i,#crlf$)
Next

Debug "-------"

For i=1 To CountString(a$,#crlf$)+1
  Debug StringField(a$,i,#crlf$ + "hello")
Next
The results of the two loops match. This shows that StringField() only used the first character of #crlf$ and only the first character of #crlf$ + "hello", both of which is the character #cr$. This result matches the description in the manual (for version 5.00).
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: #CRLF$ as StringField delimiter

Post by netmaestro »

NOBODY HERE seems to have a clue
:?:
At least try to be nice.
BERESHEIT
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: #CRLF$ as StringField delimiter

Post by Danilo »

netmaestro wrote:
NOBODY HERE seems to have a clue
:?:
At least try to be nice.
Sorry for that! Removed the blah blah.
Post Reply