Page 1 of 1

CountString gives different results...

Posted: Tue Feb 01, 2022 10:13 am
by Joris
Hi,

I have some textfiles which need to become split on empty lines with :
cnt=CountString(text$,#CRLF$+#CRLF$)

This works great if files are created on windows (I believe, experiencing some troubles).
Now I made the same small text-file on Ubuntu (same editor Ultra Edit as on windows).
It has empty lines, but those are not recognized ?
I've been struggling some time until I thought, it must be the text-file itself. And ... it was.
Recreated the text-file on windows and it works also on Ubuntu.
(the hex view mode, of this text-file, in UE shows no difference)

This must be related to those #PB_UTF8 and #PB_Unicode settings I think.
But how or where can I detect these differences or see if the file is created on windows or Ubuntu.
I would like to have use of bothh type of text-file, no matter if they were made on windows or Ubuntu.

The only place I can think of where this difference can be is inside this part (but I have no idea) :

Code: Select all

Procedure.s File_Into_Mem(file$, flag.i=#PB_File_SharedRead | #PB_UTF8)  
   Protected open.i

   Free_File_Mem()
   open=ReadFile(#PB_Any,file$,flag) 
   
   If open    
      MyFileBuffer=AllocateMemory(Lof(open)) 
      MyFileSize=Lof(open)
      FileBuffersSize(open, 0)      
      ReadData(open,MyFileBuffer,Lof(open))
      CloseFile(open)            
     ProcedureReturn PeekS(MyFileBuffer, MyFileSize, #PB_UTF8) 
  EndIf
  ProcedureReturn ""
   
EndProcedure
Thanks.

Re: CountString gives different results...

Posted: Tue Feb 01, 2022 11:06 am
by Marc56us
cnt=CountString(text$,#CRLF$+#CRLF$)

This works great if files are created on windows (I believe, experiencing some troubles).
Now I made the same small text-file on Ubuntu (same editor Ultra Edit as on windows).
It has empty lines, but those are not recognized ?
Hi Joris,

I'm not sure I understood everything, but this can't work with Linux (and all unix) with a file created on linux/unix.
Ligne separator on *nix is #LF$ (Chr(10) not #CRLF$ (Chr(13) + Chr(10))
If the file is created on windows, it can be read from linux (but sometime display CR as ^M at end of line)
(old mac use #CR$)

:wink:

Re: CountString gives different results...

Posted: Tue Feb 01, 2022 11:31 am
by Joris
Yeah, that does it too on Ubuntu : CountString(text$,#LF$+#LF$)

Thanks.

Re: CountString gives different results...

Posted: Tue Feb 01, 2022 1:31 pm
by NicTheQuick
Only Windows does this CR+LF thing. In the past MacOS uses only CR but now also uses just LF like every *nix system.