To manipulate a text file.

From Pb7

1) I want to open a text file namely "c:\temp\sidmenu.txt"
2) Read the 1st line into memory.
3) If the line does not contain the word "i_stParm.szDataWindow" then delete the line and read next line.
4) If the line contain the word "i_stParm.szDataWindow" then keep this line and read next line.

at the end the text file would have lines, where each line would contain the word "i_stParm.szDataWindow"
Who is Participating?
sandeep_patelConnect With a Mentor Commented:
Hi Mateen,

If you remember the solution i gave to find and replace the word in your file, you can use same code here also

integer li_filenum,li_filenum2
string ls_line
blob lb_text
string ls_filename
string ls_temp

long start_pos=1
string ls_old_value, ls_new_value , ls_mystring

ls_old_value =  "i_stParm.szDataWindow"
ls_new_value= ""

ls_filename = c:\temp\sidmenu.txt'          // original file
ls_temp = 'c:\temp\sidmenu_copy.txt'     // Temporary file

li_filenum = FileOpen(ls_filename,LineMode!,Read!,LockWrite!)
li_filenum2 = FileOpen(ls_temp,LineMode!,Write!,LockWrite!,Replace!)
Do While FileRead(li_filenum,ls_line) > 0
     ls_mystring = ls_line
     // Find the first occurrence of old_str.
     start_pos = Pos(ls_mystring, ls_old_value, 1)
     // Only enter the loop if you find old_str.
     If start_pos > 0 Then
           Continue ;
          ls_line = ls_mystring          
    End If



li_filenum = FileOpen(ls_temp,LineMode!,Read!,LockWrite!)
li_filenum2 = FileOpen(ls_filename,LineMode!,Write!,LockWrite!,Replace!)

Do While FileRead(li_filenum,ls_line) > 0


NOTE : I have not checked the code, simply i copied old source and modified it accordingly.

MateenAuthor Commented:

I should be able to manage it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.