Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String Erase.
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: Wed Dec 21, 2005 8:11 pm   Post subject: String Erase.

I got bored so I did this.
code:
/* The program erases a specific string from the main string at all the locations it can be found.
 W param = main string
 E param = sub string that needs to be erased
 By : MysticVegeta
 */

fcn stringErase (w : string, e : string) : string
    if length (e) > length (w) then
        result "Error: Length of parameter 'e' exceeds the length of original string."
    end if
    var fw := w
    loop
        var ind := index (fw, e)
        exit when ind <= 0
        fw := fw (1 .. ind - 1) + fw (length (e) + ind .. *)
    end loop
    result fw
end stringErase

put stringErase (" I hate you hate you hate you and will always hate you", "hate")
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: