Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hpyhde4!hpycla!hpcuhc!hpcupt3!defaria@hpcupt3.cup.hp.com From: defaria@hpcupt3.cup.hp.com (Andy DeFaria) Newsgroups: comp.lang.pascal Subject: Re: Dose anybody have space det. code!!!!!!!!! Message-ID: <45670012@hpcupt3.cup.hp.com> Date: 27 Apr 91 00:02:24 GMT References: <1991Apr23.155720.1561@e2big.mko.dec.com> Organization: Hewlett Packard, Cupertino Lines: 20 >/ hpcupt3:comp.lang.pascal / sag@iplmail.orl.mmc.com (Steve Gabrilowitz) / 12:09 pm Apr 23, 1991 / >|> > 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 - } ^ >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 ;-) I agree but... Of course you made the mistake of using underscore (_) where it seems a hyphen was intended (-).