Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!ncar!mephisto!prism!gitpyr!mlw From: mlw@pyr.gatech.EDU (Michael Williams) Newsgroups: comp.lang.pascal Subject: Re: CASE for Strings? (MS-Dos TP) Message-ID: <10010@pyr.gatech.EDU> Date: 13 Apr 90 22:03:58 GMT References: <8001@hydra.gatech.EDU> Reply-To: mlw@pyr.UUCP (Michael Williams) Organization: Georgia Institute of Technology Lines: 34 In article <8001@hydra.gatech.EDU> ce1zzes@prism.gatech.EDU (Eric Sheppard) writes: >I wish to perform functions according to commands parsed into a string array. >The CASE operator only works for simple variable types. Is there an elegant way >to perform the CASE for complex (string) variables? Desired sample construct: > >case Command of > '1STCOM' : FirstCommand; > '2NDCOM' : SecondCommand; > . > . >end; The closest constuct I know of is : valid := '1STCOM 2NDCOM 3RDCOM 4THCOM 5THCOM'; case pos(command,valid) of 1 : FirstCommand; 8 : SecondCommand; 15 : ThirdCommand; 22 : FourthCommand; 29 : FifthCommand; else write('Invalid command!'); end; This sounds like a scanner for a compiler, where you are checking for keywords. In this case, a 'perfect' hashing function would be preferable. Hope this helps ... -- Michael Williams Georgia Institute of Technology, Atlanta Georgia, 30332 uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!mlw ARPA: mlw@pyr.gatech.edu