Computer Science Canada Scanning a File |
| Author: | Prince Pwn [ Tue Jan 02, 2007 1:42 pm ] | ||
| Post subject: | Scanning a File | ||
How would I be able to scan a text file for any given word or phrase (letters in a row) and have seen by my program? I understand my problem, my get:* reads the whole line, therefore cannot see the specific word I want. In the code below, I am searching the code itself for the phrase "File_ID" but has to be on it's own line. I think it would have something to do with determining the length of the Search_Term then scanning my whole file using for loops in a major loop until it matches the correct '6' letters in a row. I am unsure of how to go about this:
|
|||
| Author: | neufelni [ Tue Jan 02, 2007 7:23 pm ] | ||
| Post subject: | |||
You can use the index function to do this. It has the following form:
It will return the position in which the substring is found in the string. From Turing Help: Quote: This program outputs 2, because "ill" is a substring of "willing", starting at the second character of "willing".
var word : string := "willing" put index ( word, "ill" ) If the substring is not in the string then it returns 0. So you can read in an entire line from your text file, and then use the index function to see if it contains a specific word. |
|||