Page 1 of 1
Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 12:22 pm
by Erlend
Please test following code, I do believe this is a bug?
What results do you get on line 1 and 2? I get Found at 2 on both... clearly it should be 1 and 2 ?
Code: Select all
;
;
NewList content.s()
ClearList(content())
file=OpenFile(#PB_Any, #PB_Compiler_File)
While Eof(file)=0
AddElement(content())
content() = ReadString(file)
Wend
CloseFile(file)
ResetList(content())
While NextElement(content())
res = FindString(content(),";")
Debug content()+" found ';' at "+Str(res)
Wend
BR
Erlend 'Preacher' Rovik
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 1:32 pm
by NicTheQuick
No, that's not a problem with `FindString()`. It's because the first line also contains the BOM. If you add `ReadStringFormat(file)` directly after `OpenFile()` everything works fine.
But I would agree that the BOM better should be skipped automatically to make it easier to work with that kind of text files.
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 1:50 pm
by breeze4me
NicTheQuick wrote: Sat Jan 31, 2026 1:32 pm
But I would agree that the BOM better should be skipped automatically to make it easier to work with that kind of text files.
There is the #PB_File_BOM flag, but it cannot be used with the #PB_Any value due to an error.
viewtopic.php?t=88265
Code: Select all
;
;
NewList content.s()
ClearList(content())
OpenFile(0, #PB_Compiler_File, #PB_File_BOM)
While Eof(0)=0
AddElement(content())
content() = ReadString(0)
Wend
CloseFile(0)
ResetList(content())
While NextElement(content())
res = FindString(content(),";")
Debug content()+" found ';' at "+Str(res)
Wend
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 1:56 pm
by Erlend
@NicTheQuick & @breeze4me:
Great, thanks a lot, you guys rule.
BR
Erlend 'Preacher' Rovik
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 2:37 pm
by Kiffi
Extra tip: In this case, don't use
OpenFile(), but
ReadFile() (you don't want to write anything into the file).
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 2:39 pm
by NicTheQuick
breeze4me wrote: Sat Jan 31, 2026 1:50 pm
NicTheQuick wrote: Sat Jan 31, 2026 1:32 pm
But I would agree that the BOM better should be skipped automatically to make it easier to work with that kind of text files.
There is the #PB_File_BOM flag, but it cannot be used with the #PB_Any value due to an error.
viewtopic.php?t=88265
I didn't know about that flag. I am on Version 6.21 and there that flag does not exist.
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 3:08 pm
by Erlend
@Kiffi: yes I know it seems wrong, but it is only a sample to show the fault, the full code actually is made so it can
add stuff like #PB constants, PB functions etc from other files / input, read at compile time, should read it in at run time instead maybe..
(it is a syntax editor, from ground up

) .
BR
Erlend 'Preacher' Rovik
Re: Findstring, Is this a bug?
Posted: Sat Jan 31, 2026 3:12 pm
by Drone
Hi
I used FileSeek(file, 3) but ReadStringFormat(file) is better.
Re: Findstring, Is this a bug?
Posted: Mon Feb 02, 2026 10:15 am
by AZJIO
Drone wrote: Sat Jan 31, 2026 3:12 pm
Hi
I used FileSeek(file, 3) but ReadStringFormat(file) is better.
The label can be 4 bytes. Always call ReadStringFormat() to move the pointer to the data.
Re: Findstring, Is this a bug?
Posted: Mon Feb 02, 2026 12:42 pm
by Drone
AZJIO wrote: Mon Feb 02, 2026 10:15 am
Drone wrote: Sat Jan 31, 2026 3:12 pm
Hi
I used FileSeek(file, 3) but ReadStringFormat(file) is better.
The label can be 4 bytes. Always call ReadStringFormat() to move the pointer to the data.
Thank you AZJIO.