Computer Science Canada Problem with sequential files and output |
Author: | caldrium [ Thu Dec 22, 2005 4:52 pm ] |
Post subject: | Problem with sequential files and output |
open : data, "hideandseek.seq", get assert (data > 0) originalword := "wonderland" for yy : 1 .. 2 for xx : 1 .. length(originalword) %loop %exit when eof (data) get : data, word (xx) if word(yy)(xx) = originalword (xx) then put word (yy) (xx) .. else put "-" .. end if %end loop end for put "" end for this is what i got so far (its a big mess), what im trying to do would be like ORIGINAL WORD :wonderland (dont need to output this as of now) WORD: DISPLAY: wonder wonder---- because wonder is in that way of wonderland, when i get output all i get is wonder "no ----" and this is crutial because i have to output other forms of words in weird orders (example : w---e---n-) can i get some help please? my sequential file is : wonder now new lend landed wand wander wood zzz |
Author: | Tony [ Fri Dec 23, 2005 12:05 am ] |
Post subject: | |
I think index() is a good function to use here. It will tell you if one string is a substring in another, and if so - the position where it first occurs. |
Author: | MysticVegeta [ Fri Dec 23, 2005 12:46 pm ] |
Post subject: | |
Careful though, index only gives the location of first character. For example : if you go something like this -> put index("wonderland", "wonder") Ouput will only be 1. To separate wonderland it would be something like this -> put str(index("wonderland", "wonder")..index("wonderland", "wonder) + length("wonder")-1) Note: I didnt test the code but its pretty straightforward. Str -> main string = "wonderland" So, what the program does it retrives the substring "wonder" from it so its really put str(1..1+6-1) = "wonder" |