From: Harold.Ruby@farwest.FidoNet.Org (Harold Ruby) Sender: Uucp@farwest.FidoNet.Org Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!menudo.uh.edu!buster!nuchat!farwest!Uucp Newsgroups: comp.lang.pascal Subject: Re: case (string) of Message-ID: <676445035.2@farwest.FidoNet> Date: 08 Jun 91 13:51:11 CST on 6 Jun 91 11:26:01 -Unknown- said to All >You have to be careful with counting, though. I wish Pascal >allowed such case >statements. I think TP3 did (Can anyone confirm this?). I used >to think the >reason was it generated code to index an array of labels (which >would be >very fast), but at least Turbo Pascal 5 doesn't - it does a >series of tests, >which would adapt well to strings, surely. > >By the way, be careful with... >> possible="DIR CLS SET MATCH"; >> { notice that all are 5 wide! } >> test="SET"; >> found=(pos(test,possible)/5); >> if (found<>0) then >> case found of >> 1: begin /*perform stuff for DIR here*/ end; >> 2: begin /*perform stuff for CLS here*/ end; > >because (a) you really need something like: possible:=' Actually, you have to be careful with your example as well: on 6 Jun 91 11:26:01 -Unknown- said to All >const Possible : string = 'CLARKSON,3COM,SNEAKER'; > >case pos(Net+',',Possible) of > 1 : DoClarksonStuff; > 10 : Do3ComStuff; > 15 : DoSneakerStuff; > else writeln('Invalid! Choose from: ',Possible); > end {of case}; Cont Possible : string = 'CLARKSON,3COM,SNEAKER,'; Note the comma --------^ If you're going to check for a "case pos(net+',',Possible)" you need that comma or poor sneaker will never see the light.. Harold * Origin: !/\/\egalon (1:106/1999)