Finding a word in a file

Blitz3D Forums/Blitz3D Beginners Area/Finding a word in a file

MattVonFat(Posted 2004) [#1]
Say i have a word which i want to look up in a file, how would i do this. Im sure its very simple but i have looked at the command reference and in the code archive.

Can anyone help?


EOF(Posted 2004) [#2]
Here is something to get you started:
find$="sublicense"
txtfile$="textdoc.txt"

file=ReadFile(txtfile$)
If file
	flag=False : lcount=0
	While Not Eof(file)
		l$=ReadLine$(file) : lcount=lcount+1
		pos=Instr(l$,find$)
		If pos>0
			flag=True
			Print "Found ["+find$+"] at position "+pos+" in line "+lcount
		EndIf
	Wend
	CloseFile file
EndIf

If flag=False Print find$+" not found in "+txtfile$
a$=Input$("Press RETURN to end")
End

I used the above on this text file called 'textdoc.txt'
This agreement gives you a limited right of use only,
which is revocable in accordance with this License Agreement.
You agree that You will not assign, sublicense, transfer, pledge,
lease, rent or share Your rights under this License Agreement.
You may not sell Your rights to a Third Party without prior written
permission from the Licensor. In the case of such a sale You must
pass all material received to the approved Third party, and any
backup copy in Your possession must be erased or otherwise destroyed.



MattVonFat(Posted 2004) [#3]
Thanks very much! :) It looks a bit confusing but i am starting to work it out. Thanks again!!!!


Kevin_(Posted 2004) [#4]
Seems a long-winded way of doing things. Here is another way to do it...

name$="Blitz Basic"
find$="it"
location = Instr( name$,find$,1)
Print "Your string contains '"+find$+"' at position number " + location

This is assuming that the file is loaded into a string.