Hi
Don't know what pre- and post-conditions you want to assert for this
routine (whether it contains consecutive spaces? By the time you find that
you're already halfway into the routine), but here's what I came up with
(if I didn't misunderstand what you want as output). This I coded using
BlackBox:
PROCEDURE RemoveExtraSpaces*(VAR s, result: ARRAY OF CHAR);
VAR i, k, pos: INTEGER;
BEGIN
s := s+' ';
i := 0; Strings.Find(s, ' ', i, pos);
k := 0;
WHILE pos # -1 DO
IF pos-i > 1 THEN
WHILE i <= pos DO result[k] := s[i]; INC(k); INC(i) END ;
END ;
i := pos+1; Strings.Find(s, ' ', i, pos);
END ;
result[k] := 0X;
END RemoveExtraSpaces;
It only checks the difference between two constantly updated indeces, one
hunting for the next space while the other trailing it, and if their
difference is more than one, copies what is between them.
Hope it does the job.
-- Ken
--
Message posted using
http://www.talkaboutprogramming.com/group/comp.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html


|