Solved

Advice for processing strings/text?

Posted on 1997-12-15
4
143 Views
Last Modified: 2010-04-04
I am just interested in some advice on this one, as many times I have done something new in Delphi only to find out later I could have done it alot easier! :-)
I am looking for advice on processing a text file. What I plan on doing is reading a text file, parsing it line by line, and char by char, and updating this same text file.
I may be removing lines, adding lines, or removing chars in the line.  Because I really haven't done much text file processing like this in Delphi, my initial plans are to open the file, read the the line into an array, parse through it, and rewrite this line back to the file (or maybe just ignore it and get the next line).
I understand this is a brief explanation, but I am assuming that reading each line into an array an parsing through the array is the best way in Delphi.  Can someone point me in the right direction on this, and is there some other way which I should research before doing it this way?

             Thanks a bunch
0
Comment
Question by:jexd99
[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
4 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353734
What about reading it in a memo, and do all your stuff in there?
Like adding, deleting, ... lines, chars, ... .
You can create a memo at run-time or you place an invisible memo component on the form.
Don't know if this is the best way, just an idea (Normally I would do it like you, but the memo has already some handy functions/procedures)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353735
Like this :

 var MyText : TMemo;

 begin
  MyText := TMemo.Create(self);
  with MyText do begin
   Clear;
   Lines.LoadFromFile('HereNameOfFile');
   { Do your stuff }
     // e.g.
     // delete line 3
      Lines.Delete[2]
     // add a line
      Lines.Add('I add this line');
    { end }
    { save the result to a file }
    Lines.SaveToFile('NameOfFile');
  end;
  MyText.Free;
  MyText := nil;
 end;
 

0
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 30 total points
ID: 1353736
Jex,

  Zif has a good answer and allows you to see what is happening but if I just wanted something quick & dirty, no-frills, grind-the file parsing doohicky I'd just open the input file (source) and an output file (destination) read the stuff in line by line chopping, hacking, etc and write out to the second file what I wanted to keep. And then delete the source file, and rename the "Destination" file to the same name as the previously-deleted source file..

Good luck with your project!
Pegasus
0
 

Author Comment

by:jexd99
ID: 1353737
Thanks to both of you. These are a couple of ideas I was looking for. I was considering the delete/rename option, and I'm not real familiar with the memo comonent, but I'll dig into it.  It seems like everytime I do something new I find out 5 months later that I could have done it a diff way with 1/2 the code! I just wanted to make sure I wasn't missing something this time around. :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 47
Twebbrowser in Fire monkey android scrolling to bottom 1 67
Firemonkey Tcameracomponent resultion 1 22
Firemonkey Queue list 1 28
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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