Newsgroups: comp.lang.pascal
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!iplmail!iplmail!sag
From: sag@iplmail.orl.mmc.com (Steve Gabrilowitz)
Subject: Re: Dose anybody have space det. code!!!!!!!!!
Message-ID: <1991Apr23.190913.7398@iplmail.orl.mmc.com>
Sender: sag@iplmail (Steve Gabrilowitz)
Organization: Martin Marietta
References: <1991Apr23.133227.10746@macc.wisc.edu> <1991Apr23.155720.1561@e2big.mko.dec.com>
Date: Tue, 23 Apr 1991 19:09:13 GMT

In article <1991Apr23.155720.1561@e2big.mko.dec.com>, granoff@vaxwrk.enet.dec.com (Mark H. Granoff) writes:
|> In article <1991Apr23.133227.10746@macc.wisc.edu>, pschwart@vms.macc.wisc.edu (Paul Schwartz) writes:
|> >    In Turbo Pascal you can treat a string like an array, therefore
|> >
|> >    for i := 1 to length(my_string) do   { for each char in the string }
|> >    	if my_string[i] = chr(20) then   { if the char is a space }
|> >    		my_string[i] = chr(45)   { replace it with a - }
|> 
|> Your example is fine, but your numeric base is wrong, once. :-)  
|> 
|> Replace chr(20) with either chr(32) or #32.  ASCII 32 is a space, not 20. 
|> However, 20 hex is 32 decimal, so I guess you are forgiven. :-)

A perfect example of why the code should have been written as:

  for i := 1 to length(my_string) do
    if my_string[i] = ' ' then
      my_string[i] := '_';

Easier to read, harder to make silly mistakes, and more portable (in  case you have some insane urge to port the program to an EBCDIC machine for example ;-)

-- 




                            Steve Gabrilowitz
                            Martin Marietta, Orlando Fl.
                            sag@iplmail.orl.mmc.com
                            Fidonet 1:363/1701
