[Implemented] StringField() empty string out-of-range
[Implemented] StringField() empty string out-of-range
I request that StringField() return an empty string for out-of-range indexes.
As of PB 4.41 it does this if the index is too high, but not if it is too low (< 1).
If it is too low it is returning the same result as it would if the index were 1.
As of PB 4.41 it does this if the index is too high, but not if it is too low (< 1).
If it is too low it is returning the same result as it would if the index were 1.
Re: StringField() return empty string for out-of-range index
I put sometimes the false index (0) in my code (FindString) and it works. Why will you change this?
I would request: only a compilerwarning, but code should work as in all pb-versions!
I would request: only a compilerwarning, but code should work as in all pb-versions!
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: StringField() return empty string for out-of-range index
@ts:
well, it fact it did not work, it just did not crash.
as you see, when you start with 0 the result is wrong because the first field is returned twice.
in the discussion thread I voted that this is not to be called a bug,
just take care not to request invalid indices below 1.
well, it fact it did not work, it just did not crash.
Code: Select all
a$ = "one,two,three,four"
Repeat
b$ = StringField(a$,field,",")
field +1
Debug b$
Until b$ = ""
in the discussion thread I voted that this is not to be called a bug,
just take care not to request invalid indices below 1.
oh... and have a nice day.
Re: StringField() return empty string for out-of-range index
@ts-soft: Code should work as in previous versions of PB, since the behavior wasn't defined for out-of-range indexes
I believe you spoke against changing it based on speed concerns. If the needed fix is that a check of the indexes be coded prior to calling StringField() then I think this could be done faster natively.
Perhaps a simple help file update could be made instead of a feature request. I'll leave that to the Admins.
@Kaeru Gaman: I agree that it is not a bug. It just seems peculiar. Here is a sample work-around that does what I requested:Kaeru Gaman wrote:@ts:
well, it fact it did not work, it just did not crash.as you see, when you start with 0 the result is wrong because the first field is returned twice.Code: Select all
a$ = "one,two,three,four" Repeat b$ = StringField(a$,field,",") field +1 Debug b$ Until b$ = ""
in the discussion thread I voted that this is not to be called a bug,
just take care not to request invalid indices below 1.
Code: Select all
a$ = ",one,two,three,four"
c = CountString(a$,",")
Repeat
b$ = StringField(a$,field + 1,",")
field +1
Debug b$
Until field > c + 1
Perhaps a simple help file update could be made instead of a feature request. I'll leave that to the Admins.
Re: StringField() return empty string for out-of-range index
An empty string suggests nothing between two fields. By returning the whole string you can actually compare your result to assess a "done" condition without knowing the number of fields ahead of time.
Re: StringField() return empty string for out-of-range index
That's a good point.Mistrel wrote:An empty string suggests nothing between two fields. By returning the whole string you can actually compare your result to assess a "done" condition without knowing the number of fields ahead of time.
Code: Select all
a$ = "too_low,one,two,three,four,too_high"
c = CountString(a$,",")
Repeat
b$ = StringField(a$,field + 1,",")
field +1
Debug b$
Until field > c + 1
Re: StringField() return empty string for out-of-range index
While it's not strictly speaking a bug (undocumented behavior), a runtime debugger check has been added and it will return a null string if < 1 is used.
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: StringField() return empty string for out-of-range index
So just to confirm: this runtime debugger check (and the extra code it uses) will NOT be present in final executables, right?
Re: StringField() return empty string for out-of-range index
No, debugger runtime check are only added to the executable when the debugger is activated.
Re: StringField() return empty string for out-of-range index
You could return the seprator string in case of invalid index.
It's variation of Mistrels suggestion.
It's variation of Mistrels suggestion.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
Re: StringField() return empty string for out-of-range index
Considering as how I rely on the current implementation I would rather this not be changed. It's more convenient to have it return the entire string when exceeding the index count than otherwise.
Re: StringField() return empty string for out-of-range index
I dunno, Mistrel, but it just might make sense do return an empty string. I mean, there's nothing there, so why should it return anything?
Take the string "a||c|d|", it contains 5 elements:
1 "a"
2 ""
3 "c"
4 "d"
5 ""
Now there's nothing at position 6, 7, 8 and so on, so to me it makes sense to return an empty string
And if that applies to ound of bounds on the right side, then I would expect the same behaviour on the left side.
Oh well, it's all a matter of taste, I guess
Take the string "a||c|d|", it contains 5 elements:
1 "a"
2 ""
3 "c"
4 "d"
5 ""
Now there's nothing at position 6, 7, 8 and so on, so to me it makes sense to return an empty string

Oh well, it's all a matter of taste, I guess

Last edited by blueznl on Wed Mar 03, 2010 7:54 pm, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: StringField() return empty string for out-of-range index
if... what?blueznl wrote:Oh well, it's all a matter of taste, I guess
Somehow it does seem sensible to me if

- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: StringField() return empty string for out-of-range index
I'm not sure if I will like to see differences in program execution between debugger mode and non debugging modeFred wrote:While it's not strictly speaking a bug (undocumented behavior), a runtime debugger check has been added and it will return a null string if < 1 is used.

This won't make debugging easier, what do you think?
Michael


Re: StringField() return empty string for out-of-range index
What do you mean? Its legal input remains the same. Only it fails more gracefully.Michael Vogel wrote:I'm not sure if I will like to see differences in program execution between debugger mode and non debugging modeFred wrote:While it's not strictly speaking a bug (undocumented behavior), a runtime debugger check has been added and it will return a null string if < 1 is used.![]()
This won't make debugging easier, what do you think?
Michael
Or do we have already other functions which are not working identical when debugging is switched on or off -- just not recognized by me
In my opinion, it should be legal to use out-of-bounds fields, and these should return null strings. This way the command is more forgiving, and in some situations it may be useful.