alternating string replace

Gordon C gc284 at vif.com
Wed Jan 9 19:33:31 EST 2008


This is very cool stuff but I suspect that the code is unreadable to many 
readers, including me. Just for fun here is a complete program, written in 
Turbo Pascal, circa 1982, that does the job. Readable n'est pas?

Program dash;
var str: string[80];
      n: integer;
      odd: boolean;
begin
    str:='Hi there_how are you?_';
    odd::=TRUE;
    for n:= 1 to length(str) do begin
      if ((str[n]='_') and (odd=TRUE)) then begin
         str[n]:= ',';
         odd:=FALSE;                                  end
      else
          if ((str[n]='_') and (odd=FALSE) then begin
             str[n]:= ':';
             odd:= TRUE;                                    end;
    end; {for}
    writeln(str);
    end. {dash}

Regards,
Gord 





More information about the Python-list mailing list