Computer Science Canada

String Erase.

Author:  MysticVegeta [ 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")


: