Solved

To manipulate a text file.

Posted on 2006-06-26
2
1,040 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

710 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