Page 1 of 1
[SOLVED] FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:28 am
by Randy Walker
Is there a trick to doing a search using findString() to find a string that is prefaced with CRLF? I tried something like this but no joy:
Code: Select all
search = #LFCR$+"Word"
If OpenFile(0,filename$)
text.s = ReadString(0,#PB_Ascii | #PB_File_IgnoreEOL)
CloseFile(0)
EndIf
Debug FindString(text,search)
For my test, the filename$ looks like this:
Code: Select all
first line
Word beginning second line.
last line.
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:34 am
by Cyllceaux
Hi,
Easy... it is
#CRLF$ not
#LFCR$
Code: Select all
search.s = #CRLF$+"Word" ; <--- Here
If OpenFile(0,"c:\temp\test.txt")
text.s = ReadString(0,#PB_Ascii | #PB_File_IgnoreEOL)
CloseFile(0)
EndIf
Debug FindString(text,search) ; 11
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:35 am
by idle
maybe just search for #LF$+"word"
not all files will have #CRLF$
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:53 am
by Randy Walker
idle wrote: Wed Aug 27, 2025 5:35 am
maybe just search for #LF$+"word"
not all files will have #CRLF$
tried that and still no joy. I inspected the file using hex editor and definitely see 0d 0a 57 6f 72 64 so the #CRLF$ should be proper.
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 7:17 am
by idle
What happens if you Debug the search string
Does FindString need a flag to skip #crlf$
Sorry I'm away from the computer

Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 7:44 am
by jacdelad
Whenever im not sure what kind of new line is used (LF, CR, CRLF...) I replace all LF with CR and then all CRCR repeatedly with CR. Now I can search for CR+string (given that empty lines don't play a role).
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 8:08 am
by TassyJim
It works for me. PB6.21
Code: Select all
search.s = #CRLF$+"Word"
filename$ = "C:\\apps\teststr.txt"
If OpenFile(0,filename$)
text.s = ReadString(0,#PB_Ascii | #PB_File_IgnoreEOL)
CloseFile(0)
EndIf
text2.s = "first line"+#CRLF$+"Word beginning second line."+#CRLF$+"last line."
Debug StringByteLength(text) ;102
Debug StringByteLength(text2) ;102
Debug Len(text) ;51
Debug Len(text2) ;51
Debug FindString(text,search) ;11
Debug FindString(text2,search) ;11
I compared a file read and a string.
Both len() and stringbytelength() included the #CRLF$ pairs in the result.
Findstring gives the correct answer including the #CRLF$
Jim
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 9:28 am
by Little John
FindString() treats the characters CR and LF in the same way as most other characters, e.g. ‘a’ or ‘b’.
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 4:48 pm
by Randy Walker
idle wrote: Wed Aug 27, 2025 7:17 am
What happens if you Debug the search string
Does FindString need a flag to skip #crlf$
Sorry I'm away from the computer
When I "debug search" I get a line feed followed by the next line beginning with "Word".
This:
Code: Select all
search.s = #CRLF$+"Word" ; <--- Here
If OpenFile(0,"c:\Tmp\test.txt")
text.s = ReadString(0,#PB_Ascii | #PB_File_IgnoreEOL)
CloseFile(0)
EndIf
Debug FindString(text,search)
Debug search
Gives me this:
Code: Select all
0 ;Top line in debug window
;Blank line
Word ;Bottom line
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 4:56 pm
by Randy Walker
TassyJim wrote: Wed Aug 27, 2025 8:08 am
It works for me. PB6.21
Jim
Ok, I guess (like always) I should have mentioned I was using PB6.20
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 4:59 pm
by Randy Walker
Little John wrote: Wed Aug 27, 2025 9:28 am
FindString() treats the characters CR and LF in the same way as most other characters, e.g. ‘a’ or ‘b’.
Ok but, I still get zero when I reduce down to search.s = #CRLF$
(again, I am using PB6.20)
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:44 pm
by SMaag
k but, I still get zero when I reduce down to search.s = #CRLF$
(again, I am using PB6.20)
The problem seems to be the String you read from the file.
Code: Select all
search.s = #CRLF$ + "Word"
txt.s = "blablablablabla" + #CRLF$ + "Word"
p = FindString(txt, search)
Debug p
Re: FindString() with CRLF in the search?
Posted: Wed Aug 27, 2025 5:48 pm
by Randy Walker
TassyJim wrote: Wed Aug 27, 2025 8:08 am
It works for me. PB6.21
Jim
I uninstalled 6.20, installed 6.21 and now seems to be working OK
Thanks Jim