Solved

To manipulate a text file.

Posted on 2006-06-26
2
1,034 Views
Last Modified: 2013-12-26
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"
0
Comment
Question by:Mateen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
sandeep_patel earned 500 total points
ID: 16982612
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 ;
     Else
          ls_line = ls_mystring          
    End If

   FileWrite(li_filenum2,ls_line)
Loop

FileClose(li_filenum)
FileClose(li_filenum2)

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
   FileWrite(li_filenum2,ls_line)
Loop

FileClose(li_filenum)
FileClose(li_filenum2)

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

Regards,
Sandeep
0
 

Author Comment

by:Mateen
ID: 16982854
Thanks

I should be able to manage it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question