by "Xcriber51" <ken@[EMAIL PROTECTED]
>
Oct 29, 2007 at 12:51 PM
The previous version is a bit confused and inefficient. It traverses the
string twice: once when hunting for spaces in the string with the
"Strings.Find" call, and a second time when copying a ****tion of it.
Here's a simpler, a more primitive but hopefully clearer version.
PROCEDURE RemoveExtraSpaces2*(VAR s, result: ARRAY OF CHAR);
VAR i,j,k: INTEGER;
ch: CHAR;
BEGIN
j := -1; k := 0;
FOR i := 0 TO LEN(s$) DO
ch := s[i];
IF ch # ' ' THEN
result[k] := ch; INC(k)
ELSE
IF (i-j) > 1 THEN result[k] := ch; INC(k) END ;
j := i
END ;
END ;
DEC(k);
IF result[k-1] = ' ' THEN DEC(k) END ;
result[k] := 0X;
END RemoveExtraSpaces2;
The last part looks like thra****ng about a bit, but the trailing spaces
are tricky and I didn't want to make a call to the "Trim" function.
-- Ken
--
Message posted using
http://www.talkaboutprogramming.com/group/comp.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html