[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: GNU Pascal..............



On Thu, Oct 28, 1999 at 01:12:50PM -0300, Phillip Neumann wrote:
> Hello, im having a little problem here with pascal.

It's been YEARS, so take the following with a Syberian salt mine...

> i want to emulate somethig like in bash would be: 
> for b in a do; echo $b  , where a,b are strings.

Look up pos, substr, and delete.

pos takes two strings as paramters--the first to be found in the
second--and returns the location of the first match.  substr takes a
couple bytes and a string, the first is the starting position, the second
is the length, and the third is the string.  delete does what substr does
but deletes from first to count chars from the string.  IFF these are all
functions and work the way I remember, you can do this..

  while pos( ' ', somestr ) > 0 do Begin
    spc := pos( ' ', somestr );
    writeln( substr( 1, spc, somestr ) );
    somestr := delete( 1, spc, somestr );
  End;
  writeln( somestr );

substr and pos are functions.  delete may not be.  If it's not then you
need to remove the somestr := part.

Um, it may be possible with GNU Pascal to do something like

  while (spc := pos( ' ', somestr )) > 0 do ...

That'd optimize things a bit if it'll do it.  It might not though, so be
careful of that.  One more thing you could do is add a space to the very
end of the string and you could get rid of that last writeln.

You may need to succ and pred a couple of those numbers, but I don't
think so.


Good luck.  =>

-- 
- Joseph Carter         GnuPG public key:   1024D/DCF9DAB3, 2048g/3F9C2A43
- knghtbrd@debian.org   20F6 2261 F185 7A3E 79FC  44F9 8FF7 D7A3 DCF9 DAB3
--------------------------------------------------------------------------
* james would be more impressed if netgod's magic powers could stop the
  splits in the first place...
* netgod notes debian developers are notoriously hard to impress

Attachment: pgp4o2es1aEnr.pgp
Description: PGP signature


Reply to: