<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'need help with textfiles (2)' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'need help with textfiles (2)' posted on the 'Pascal' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 19:23:24 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 19:23:24 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/154202/need-help-with-textfiles-2/</link>
      <description>I have a text file which has some html constructs. I have to copy this text file into a new one but without any comments (ie. if there is &amp;lt;--hello--&amp;gt;, it has to be removed from the text file. How can I do that?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/154202/need-help-with-textfiles-2/</guid>
      <pubDate>Mon, 18 Nov 2002 07:57:35 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/154292/re-need-help-with-textfiles-2/#154292</link>
      <description>: I have a text file which has some html constructs. I have to copy this text file into a new one but without any comments (ie. if there is &amp;lt;--hello--&amp;gt;, it has to be removed from the text file. How can I do that?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Heres what I would do:&lt;br /&gt;
&lt;br /&gt;
Have a boolean called InComment initially set to false.&lt;br /&gt;
Have a loop calling ReadLn to read the file line by line.&lt;br /&gt;
After reading the line have an if statement that does either:&lt;br /&gt;
&lt;br /&gt;
1) If InComment is true, check for "--&amp;gt;".  If it isnt found, ignore the whole string since its a comment.  If it is found, delete all the text up to the "--&amp;gt;" and set InComment to false and write whats left of the string.&lt;br /&gt;
&lt;br /&gt;
2) If InComment is false, check for "&amp;lt;!--".  If it is found, check for "--&amp;gt;".  If it is found, delete the text between the two sequences and write whats left of the string.  If "--&amp;gt;" isnt found, set InComment to true and erase from "&amp;lt;!--" to the end of the line, writing whats left of the string.&lt;br /&gt;
&lt;br /&gt;
The above if statement should actually be run in a while loop since its possible you may read a string that looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- comment1 --&amp;gt; blah &amp;lt;!-- comment2 --&amp;gt; blah &amp;lt;!-- comment3 --&amp;gt; blah&lt;br /&gt;
&lt;br /&gt;
And that should be all thats necessary.  It was probably harder to try to describe the steps involved than it would have been to just write the pascal program, but I thought I would leave it to you to attempt first.  If you still have problems just post what you have.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/154292/re-need-help-with-textfiles-2/#154292</guid>
      <pubDate>Mon, 18 Nov 2002 12:41:37 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/154514/re-need-help-with-textfiles-2/#154514</link>
      <description>I tried doing what you told me but I didn't manage. Can you please send me the code so that i could know what I'm doing wrong please?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/154514/re-need-help-with-textfiles-2/#154514</guid>
      <pubDate>Tue, 19 Nov 2002 09:53:16 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/154526/re-need-help-with-textfiles-2/#154526</link>
      <description>: I tried doing what you told me but I didn't manage. Can you please send me the code so that i could know what I'm doing wrong please?&lt;br /&gt;
&lt;br /&gt;
It probably wont help much because I wrote it in a rush and it's incredibly messy, but this works fine here:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
program a;

uses
  crt;

var
  inf, outf: text;
  s: string;
  comm: boolean = false;

begin
     assign(inf, 'comm.html');
     reset(inf);
     assign(outf, 'nocomm.html');
     rewrite(outf);

     while not eof(inf) do
     begin
          readln(inf, s);
          if (comm) and (pos('--&amp;gt;', s) = 0) then
             s := '';
          while (pos('&amp;lt;!--', s) &amp;gt; 0) or (pos('--&amp;gt;', s) &amp;gt; 0) do
          begin
               if (comm) then
               begin
                    if (pos('--&amp;gt;', s) &amp;gt; 0) then
                    begin
                         delete(s, 1, pos('--&amp;gt;', s) + 2);
                         comm := false;
                    end else
                    begin
                         s := '';
                    end;
               end else
               begin
                    if (pos('&amp;lt;!--', s) &amp;gt; 0) then
                    begin
                         if (pos('--&amp;gt;', s) &amp;gt; 0) then
                         begin
                              delete(s, pos('&amp;lt;!--', s), pos('--&amp;gt;', s) + 2 - pos('&amp;lt;!--', s) + 1);
                         end else
                         begin
                              delete(s, pos('&amp;lt;!--', s), length(s));
                              comm := true;
                         end;
                    end;
               end;
          end;
          if (s &amp;lt;&amp;gt; '') then
             writeln(outf, s);
     end;

     close(inf);
     close(outf);
end.
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/154526/re-need-help-with-textfiles-2/#154526</guid>
      <pubDate>Tue, 19 Nov 2002 11:14:11 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/155478/re-need-help-with-textfiles-2/#155478</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Moderator at 2002-11-23 10:32:3&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
I did exactly what you told me but no luck....my program is crashing. Here is what i wrote in my program and also here's my textfile.&lt;br /&gt;
&lt;br /&gt;
Test.PAS&lt;br /&gt;
------------------&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
Program Test;

var InFile, Outfile : Text;
    Line : string;
    Command : boolean;


begin
  {Prepare file for input and output}
  Assign(InFile, 'C:\sample.HTM');
  Reset(InFile);                  {Open InFile for input}

  Assign(OutFile, 'C:\copy.HTM');
  Rewrite(OutFile);               {Open Outfile for output}

  {Copy the data line by line}
  while not EOF(InFile) do
    begin
    Command := False;
      ReadLn(InFile, Line);
      if Command and (pos('--&amp;gt;', Line) = 0) then
        Line := '';
      while (pos('&amp;lt;--', Line) &amp;gt; 0) or (pos('--&amp;gt;', Line) &amp;gt; 0) do
        begin
          if Command then
          begin
            if (pos('--&amp;gt;', Line) &amp;gt; 0) then
              begin
                delete(Line, 1, pos('--&amp;gt;', Line) + 2);
                Command := False;
              end;
          end;
        end;
    end;
    if (Line &amp;lt;&amp;gt; '') then
      WriteLn(OutFile, Line);

  {Close file}
  Close(InFile);
  Close(OutFile)
End.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Sample.HTM&lt;br /&gt;
--------------------------&lt;br /&gt;
&amp;lt;?html version="1.0"&amp;gt;&lt;br /&gt;
&amp;lt;-- this is a comment --&amp;gt;&lt;br /&gt;
&amp;lt;scene&amp;gt;&lt;br /&gt;
&amp;lt;viewpoint from="0 0 -1" at="0 0 5" up="0 1 0"/&amp;gt;&lt;br /&gt;
&amp;lt;surface&amp;gt;&lt;br /&gt;
&amp;lt;sphere centre="0 0 5" radius="2"/&amp;gt;&lt;br /&gt;
&amp;lt;texture name="shiny_red"/&amp;gt;&lt;br /&gt;
&amp;lt;/sphere&amp;gt;&lt;br /&gt;
&amp;lt;/surface&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;light from="5 5 5"/&amp;gt;&lt;br /&gt;
&amp;lt;/scene&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;-- This is a comment --&amp;gt;&lt;br /&gt;
viewpoint&lt;br /&gt;
{&lt;br /&gt;
  from &amp;lt;0,0,-1&amp;gt;&lt;br /&gt;
  at &amp;lt;0,0,5&amp;gt;&lt;br /&gt;
  up &amp;lt;0,1,0&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object&lt;br /&gt;
{&lt;br /&gt;
  sphere &amp;lt;0,0,5&amp;gt;,2&lt;br /&gt;
  shiny_red&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
light &amp;lt;5,5,5&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/155478/re-need-help-with-textfiles-2/#155478</guid>
      <pubDate>Sat, 23 Nov 2002 07:09:04 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: need help with textfiles (2)</title>
      <link>http://www.programmersheaven.com/mb/pasprog/154202/155500/re-need-help-with-textfiles-2/#155500</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Moderator at 2002-11-23 10:39:30&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: I did exactly what you told me but no luck....my program is crashing. Here is what i wrote in my program and also here's my textfile.&lt;br /&gt;
&lt;br /&gt;
You didnt do exactly what I told you, you cut out over half of the program.  Without knowing what error message you are getting I wont know what is causing the crash, but even if you fix the crash I can tell you that what you have there will not work at all.&lt;br /&gt;
&lt;br /&gt;
Actually I just looked at the code again...from what I can see the program shouldnt crash, but it definitely will be thrown into an infinite loop.  My suggestion would be to either use my code in its entirety since I know for a fact it'll work, or to read through and fully understand the logic of it before you cut parts out.  That's where your problem lies.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/154202/155500/re-need-help-with-textfiles-2/#155500</guid>
      <pubDate>Sat, 23 Nov 2002 10:35:34 -0700</pubDate>
      <category>Pascal</category>
    </item>
  </channel>
</rss>