Hi All
I wish to search for a word in a file using BASIC language.
I can open the file.
Code:
OpenSeq FILENAME To fOpened
ReadSeq Record From fOpened
But not sure how to search for a word inside the file. Sorry now only i started to work with BASIC Language.
For example:
SUN
MOON
EARTH
I know what i need to search for the word "MOON" in the file, but not sure how to do it.
It will be great if any one can guide me in this.
Thanks
DS User
Search for a word in a file
Moderators: chulett, rschirm, roy
Is your search target always on its own as in your example? If so, then it seems a simple equality check is all you need. If the 'word' is buried in a larger string, then a function like Index() or Matches() can be used to detect a substring within a string.
Once you find it, then what?
Once you find it, then what?
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Hi craig
Thanks for your reply.
Sorry, I may not explain properly.
I am trying to implement a logic in which i need to find the specified String "I will pass it as Param" is present in the file or not?
Need is like X = cat filename | grep "MOON"
SUN
MOON
EARTH
If i write a code like below,
OpenSeq FILENAME To fOpened
ReadSeq Record From fOpened
now the first line is in Record. How to move to next line, making it in loop.
Or is there is any way to search for a specific word like cat filename | grep "MOON"
Please guide me.
Thanks
DS User
Thanks for your reply.
Sorry, I may not explain properly.
I am trying to implement a logic in which i need to find the specified String "I will pass it as Param" is present in the file or not?
Need is like X = cat filename | grep "MOON"
SUN
MOON
EARTH
If i write a code like below,
OpenSeq FILENAME To fOpened
ReadSeq Record From fOpened
now the first line is in Record. How to move to next line, making it in loop.
Or is there is any way to search for a specific word like cat filename | grep "MOON"
Please guide me.
Thanks
DS User
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Yes, the Index() function.
Code: Select all
Counter = 0
Value = DSGetParamInfo(hJob, "jpSearchString", DSJ.PARAMVALUE)
Loop
While ReadSeq Record From fOpened
Counter += (Index(Record, Value, 1) > 0)
Repeat
Ans = Counter
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.