CountString gives different results...

Linux specific forum
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

CountString gives different results...

Post 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.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: CountString gives different results...

Post 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:
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: CountString gives different results...

Post by Joris »

Yeah, that does it too on Ubuntu : CountString(text$,#LF$+#LF$)

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: CountString gives different results...

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