Solved

To manipulate a text file.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now