[comp.lang.pascal] Another Space detector algorithm

rfh3273@galileo.rtn.ca.boeing.com (Dick Harrigill) (05/08/91)

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