Page 1 of 1
Stringfield modification
Posted: Thu Oct 16, 2008 1:08 pm
by Ludo
Hey, that's my first post since registering PureBasic a few weeks ago. All to plan till now.
In the StringField function, I would allow for negative indexnumbers too. 1,2,3 ... would then start counting from the beginning of the string and -1, -2, -3 would start from the end of the string.
It is an easy thing to code myself, but it could be a usefull change after all.
Cheers,
Ludo
Posted: Thu Oct 16, 2008 2:10 pm
by Fred
Yes, you can achieve it easily with StringField(a$, ",", CountString(",")-x)
Posted: Mon Nov 10, 2008 1:10 am
by klaver
Fred wrote:Yes, you can achieve it easily with StringField(a$, ",", CountString(",")-x)
But it's much slower that way...
Posted: Mon Nov 10, 2008 2:07 pm
by Fred
Why that ? It's exactly what the function would do anyway.
Posted: Tue Nov 11, 2008 5:18 pm
by klaver
a$ = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
CountString() will first walk through the whole string from beginning counting all "," characters, and then StringField() will again walk from the beginning to find the specified occurrence of ",".
So if I'd like to get the "y" field of the string, I'd rather to use StringField(a$, ",", -2). The function should then walk from the END of the string and return the string between frist and second occurrence of the delimiter. Without wasting time on CountString() and walking form the beginning, as it's much closer from the end, isn't it?
Wouldn't it be faster and much more optimal?
Posted: Tue Nov 11, 2008 6:10 pm
by Fred
Right, i overlooked that

. Anyway, the difference won't be huge here, as walking backward isn't a good idea on nowaday processor. Here, in most of case, the whole string will be in the processor cache so the second pass will be almost free.