Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Scanning a File
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince Pwn




PostPosted: 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:

code:

procedure Scan_File (File_Location, Search_Term : string)
    var File_ID : int
    var Word : string
    open : File_ID, File_Location, get, seek
    loop
        exit when eof (File_ID)
        get : File_ID, Word : *
        if Word = Search_Term then
            colour (brightred)
        else
            colour (black)
        end if
        put Word
    end loop
    close : File_ID
end Scan_File

Scan_File ("C:/Documents and Settings/Administrator/Desktop/Scan.t", "File_ID")
Sponsor
Sponsor
Sponsor
sponsor
neufelni




PostPosted: Tue Jan 02, 2007 7:23 pm   Post subject: (No subject)

You can use the index function to do this. It has the following form:
code:
index(String, substring : string) : int

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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: