Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!bcstec!galileo!rfh3273 From: rfh3273@galileo.rtn.ca.boeing.com (Dick Harrigill) Newsgroups: comp.lang.pascal Subject: Another Space detector algorithm Keywords: strings Message-ID: <378@galileo.rtn.ca.boeing.com> Date: 8 May 91 16:28:39 GMT Article-I.D.: galileo.378 References: <1991Apr22.060051.2238@nuchat.sccsi.com> <1991Apr28.131624.7940@cc.curtin.edu.au> <1991Apr28.150459.631@cs.odu.edu> Organization: boeing Lines: 35 In a msg dated [Mon Apr 22 1991], Robert Oliver Jr. wrote (to All): > ROJ: dose any body have some code that can detect a space in a > ROJ: string[40] and replace it with a -, but if there is not a > ROJ: space then dont do anything ? There were many different solutions offered, most claiming to be the best, and many that were sick (i.e. made a simple solution extremely complex)! However, this is the absolute sickest way (ala Turbo Pascal): ---------------------------- PROGRAM tryme; PROCEDURE space_dasher (VAR s:string); TYPE byte_set = SET OF 0..7; VAR b : ARRAY [0..40] OF byte_set ABSOLUTE s; i : byte; c:char ABSOLUTE i; BEGIN FOR c:=chr(1) TO s[0] DO IF (byte(s[i]) xor $DF)=$FF THEN b[i]:=[0,2,3,5]; END; VAR s:string; BEGIN REPEAT write('>'); readln(s); space_dasher(s); writeln(' ',s); writeln(s); UNTIL s='' END. -------------------------------- If you follow this, you may never have a question about strings or bit manipulation again. -- Dick Harrigill, an independent voice from: Boeing Commercial Airplanes M/S 9R-49 PO BOX 3707 Renton Avionics/Flight Systems Seattle, WA 91824 Computing Support (206) 393-9539 rfh3273@galileo.rtn.ca.boeing.com