Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / search string please help me

Author
Message
DRYAD
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: Greece
Posted: 21st Jan 2003 10:21
Hello.
I need to make a program to search for a word from a txt file. All i want is to input a word, then the program start search for this word and display all the matching words.
It will be better if the program can display the whole line where the matching words is.
thanks in advance.
Zooker
21
Years of Service
User Offline
Joined: 27th Oct 2002
Location: United States
Posted: 26th Jan 2003 08:08
DRYAD

Try Something Like!
Z$=Upper$("Zooker")
Read$=Read String("File Name")[Not sure syntax is correct]
Read$=Upper$(Read$)
Start%=1
While Place%<>0
Place%=Instr(start%,Read$,Z$)
If Place%<>0 then print Place%
start%=Place%+1
sync
EndWhile
It's a starting Point! LoL!!

It took Years to Make Me this Stupid!
AsriCE
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 26th Jan 2003 14:57
This is exactly what you need. Enjoy

Filename$ = "File.txt"
Word$ = "Replace Word Here."

Input "Insert word: ", Word$
Open To Read 1, Filename$
Wrd = Len(Word$)

Set Cursor 0,45
Found = 0

Repeat
Read String 1, Search$
Src = Len(Search$)

Repeat
Temp1$ = Right$(Search$, Src)
Temp2$ = Left$(Temp1$, Wrd)

If Upper$(Temp2$) = Upper$(Word$)
Found = Found + 1
Text 0, 30, "Search Found: " + Str$( Found )
Print "Word: "; Temp2$
Print "Sentence: "; Search$
EndIf

Dec Src
Until Src=0
Until File End(1)=1

Close File 1
End


- Asri Crew

Anak Brunei!
DRYAD
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: Greece
Posted: 27th Jan 2003 13:45
(
Its not working :
Filename$ = "myFile.txt"
Word$ = "Replace Word Here."

Input "Insert word: ", Word$
Open To Read 1, Filename$
Wrd = Len(Word$)

Set Cursor 0,45
Found = 0

Repeat
Read String 1, Search$
Src = Len(Search$)

Repeat
Temp1$ = Right$(Search$, Src)
Temp2$ = Left$(Temp1$, Wrd)

If Upper$(Temp2$) = Upper$(Word$)
Found = Found + 1
Text 0, 30, "Search Found: " + Str$( Found )
Print "Word: "; Temp2$
Print "Sentence: "; Search$
EndIf

Dec Src
Until Src=0
Until File End(1)=1

Close File 1
End
when i run the code it shows me nothing.
it not shows me any result.
please i need it baaaad.
can anyone please help me.
i need a working code.
please
thanks in advance

xmen
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location:
Posted: 28th Jan 2003 01:51
`...................................................
`...................................................


`.......................Modify By XMEN..............


`...................................................
`...................................................

dim found$(1000)
Filename$ = "c:\filename.txt"

Input "Search For Word: ", Word$
Open To Read 1, Filename$

Wrd = Len(Word$)

Set Cursor 0,45
Found = 0

a$=" "
temp1$=""
Repeat
Read String 1, Search$

for a=1 to 256

if mid$(Search$,a)=" " then a$=""

if mid$(Search$,a)<>" "

Temp1$ =""+mid$(Search$,a)
a$=a$+temp1$
Temp2$ =a$

if len(a$)=len(Word$) then a$=""
endif

If Upper$(Temp2$) = Upper$(Word$) or lower$(Temp2$) = lower$(Word$)

Found = Found + 1

found$(found)=Search$
Text 0, 30, "Search Found: " + Str$( Found )
found$(line)=Search$
line=line+1

a$=""

exit
EndIf

next a
a$=""
a=0

Until File End(1)=1
Close File 1
cls
number=0
repeat

print "........Search For Word...... : "+" "+Word$
print
ink rgb(255,255,255),1
Print "Number of Word found : "+str$(found)
print

Print "Sentence: "+str$(number+1)+": of "+str$(found)
print
ink rgb(255,0,0),1

print found$(number)

ink rgb(255,255,255),1

print "Press Any Key"
suspend for key
cls
number=number+1

until number=line

cls
print "No more word found"
end
xmen
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location:
Posted: 29th Jan 2003 00:06
Hope this help you a bit
AsriCE
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 31st Jan 2003 01:46
Try including the directory of the .txt file.

Filename$ = "C:\YourDirectory\TextFile.txt"

And try deleting the Word$ part.

Filename$ = "File.txt"
Rem Word$ = "Replace Word Here." : <-- Delete this part

Input "Insert word: ", Word$


Hope this helps.
- AsriCE

Anak Brunei!

Login to post a reply

Server time is: 2024-05-05 05:39:02
Your offset time is: 2024-05-05 05:39:02