![]() |
|
|
|
|
|
|
2
31st October 14:16
External User
Posts: 1
|
FYI Karnaugh maps, logical equations etc. were in common use back
in the 1930s, and date back much earlier than that. Telephone systems, using relays, required lots of digital knowledge. -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> -- Posted via a free Usenet account from http://www.teranews.com |
|
|
3
31st October 14:16
External User
Posts: 1
|
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/...p.lang.oberon/ More information at http://www.talkaboutprogramming.com/faq.html |
|
|
4
31st October 14:16
External User
Posts: 1
|
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 portion 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 thrashing 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/...p.lang.oberon/ More information at http://www.talkaboutprogramming.com/faq.html |
|
|
7
31st October 18:57
External User
Posts: 1
|
FYI Karnaugh maps, logical equations etc. were in common use back
in the 1930s, and date back much earlier than that. Telephone systems, using relays, required lots of digital knowledge. -- Chuck F (cbfalconer at maineline dot net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> -- Posted via a free Usenet account from http://www.teranews.com |
|
|
|