Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

To manipulate a text file.

Posted on 2006-06-26
2
Medium Priority
?
1,050 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

722 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