Maxscript - Need help with FileStream / StringStream

Hi!
I'm writing a script but I'm stuck with this. I need a function to do the following:

1. open a .ms file
2. at the end of every "case...of ( )" statement (after the closing parenthesis), add a ';'
3. write and close the file.

I'm not good dealing with the FileStream/StringStream functions.

Help please!