Findstring, Is this a bug?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Findstring, Is this a bug?

Post 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
User avatar
NicTheQuick
Addict
Addict
Posts: 1565
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Findstring, Is this a bug?

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
breeze4me
Enthusiast
Enthusiast
Posts: 665
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Findstring, Is this a bug?

Post 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

User avatar
Erlend
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Re: Findstring, Is this a bug?

Post by Erlend »

@NicTheQuick & @breeze4me:
Great, thanks a lot, you guys rule.

BR
Erlend 'Preacher' Rovik
User avatar
Kiffi
Addict
Addict
Posts: 1520
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Findstring, Is this a bug?

Post by Kiffi »

Extra tip: In this case, don't use OpenFile(), but ReadFile() (you don't want to write anything into the file).
Hygge
User avatar
NicTheQuick
Addict
Addict
Posts: 1565
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Findstring, Is this a bug?

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Re: Findstring, Is this a bug?

Post 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
Drone
User
User
Posts: 12
Joined: Fri May 03, 2019 10:21 pm

Re: Findstring, Is this a bug?

Post by Drone »

Hi

I used FileSeek(file, 3) but ReadStringFormat(file) is better.
AZJIO
Addict
Addict
Posts: 2257
Joined: Sun May 14, 2017 1:48 am

Re: Findstring, Is this a bug?

Post 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.
Drone
User
User
Posts: 12
Joined: Fri May 03, 2019 10:21 pm

Re: Findstring, Is this a bug?

Post 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.
Post Reply