🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6412

Re: memory stream parsing

#6412
From: Vladimir Stefanovic
Date: Sun, 15 May 2005 19:19
68 lines
2938 bytes
You can easily access single bytes inside TMemoryStream, and
further make some logic by yourself.

The easiest way is to use temporary memory stream to get rid of
unnecessary "\r\n" but you still can use only (the original) one, but
with more logic involved.

This code (UNTESTED) should get rid of all "\r" or "\n", not only
sequences of them.

I's not so hard to extend the code to search for sequences only.

// UNTESTED !!! To check the code place a file "file.txt" in the
//same root where your EXE is placed, and after Button1Click, the
//second file should be created "file2.txt".

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TMemoryStream *MS_OLD = NULL;
   TMemoryStream *MS_NEW = NULL;
   try
   {
      try
      {
         MS_OLD = new TMemoryStream;
         MS_NEW = new TMemoryStream;

         MS_OLD->LoadFromFile( ExtractFilePath( ParamStr(0) ) + 
"file.txt" );

         for ( int i=0; i<MS_OLD->Size ; i++ )
         {
            if (
                 (((char*)(MS_OLD->Memory))[i] != '\r') &&
                 (((char*)(MS_OLD->Memory))[i] != '\n')
               )
            {
               MS_NEW->WriteBuffer( &((char*)(MS_OLD->Memory))[i] , 1 );
            }
         }
         MS_NEW->SaveToFile( ExtractFilePath( ParamStr(0) ) + "file2.txt" );
      }
      catch (  const Exception &e )
      {
         ShowMessage( "Error" );
      }
   }
   __finally
   {
      if ( MS_OLD )
         delete MS_OLD;
      if ( MS_NEW )
         delete MS_NEW;
   }
}


-- 
Best regards,
Vladimir Stefanovic
"xa" <pageme@ntlworld.com> wrote in message 
news:42878a87$1@newsgroups.borland.com...
>I have some html code stored in a memory stream and i need to strip out the
> "\r\n"  prior to assigning the dat afor display... can anyone show me an
> effective way of doing this please..
>
>
> 
Technical Details
Message-ID: <4287a0a4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42878a87$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cb77108e6b3d9403
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42878a87$1@newsgroups.borland.com>
Subject: Re: memory stream parsing
Date: Sun, 15 May 2005 21:19:04 +0200
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.117.212.65
Message-ID: <4287a0a4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1116184740 82.117.212.65 (15 May 2005 12:19:00 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail