Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!stanford.edu!rutgers!cmcl2!adm!news From: CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) Newsgroups: comp.lang.pascal Subject: Re: case (string) of Message-ID: <27115@adm.brl.mil> Date: 4 Jun 91 23:03:45 GMT Sender: news@adm.brl.mil Lines: 46 In article <1991Jun3.222059.16125@javelin.sim.es.com>, tpehrson@javelin.sim.es.com (Tim Clinkenpeel) writes: >so i can't use case for strings, eh? what are my alternatives? a >list of if-thens? (tp5.0) That's one option. Another is to test the strings against the elements of an array, and use the matching index as the argument for the case: type strArray : array [1..5] of string[6]; const caseStrings : strArray = ('DELETE','INSERT','SORT','REPORT','QUIT'); var inputString : string[6]; i : word; begin GetInput(inputString); inputString := UpCaseString(inputString); i := 5; while (i > 0) and (inputString <> caseStrings[i]) do Dec(i); case i of 0 : ; {no match} 1 : procDelete; 2 : procInsert; 3 : procSort; 4 : procReport; 5 : Quit; end. If you have lengthy strings or many of them, or have other objections to the "match the array" approach, then you can calculate some type of value from the string (i.e., "hash" it) and use that value as the case variable. Cheers-- --Karl +====================================================================+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta GA 30093 USA | | Home of Epi Info 5.0 | +====================================================================+