Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Oberon > Re: Weak formal...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 445 of 500
Post > Topic >>

Re: Weak formal methods ?

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
 




 4 Posts in Topic:
Weak formal methods ?
problems@[EMAIL PROTECTED  2007-10-28 20:35:38 
Re: Weak formal methods ?
CBFalconer <cbfalconer  2007-10-29 00:08:11 
Re: Weak formal methods ?
"Xcriber51" <  2007-10-29 07:43:00 
Re: Weak formal methods ?
"Xcriber51" <  2007-10-29 12:51:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 15:45:55 CDT 2008.