#define _TAB Chr(9) #define _CR Chr(13) #define _LF Chr(10) #define _DA '&' + '&' Strtofile(RemoveComments('c:\temp\removecomments.prg'), 'c:\temp\test.prg') function RemoveComments lparameters tcProgram * This program will remove all lines that starts with a *, for they are comments ; but it will also remove all the comments continuation, like this oneline as well ; as all the remaining text after the && comments * tcProgram is a mandatory parameter if Vartype(tcProgram) # 'C' or Empty(tcProgram) or not File(tcProgram) return .f. endif local lcProgramText, i, lnMemoWidth, llCont, llRemove, lnPos, lcNewProgramText, llWasComment, llCommentCont lnMemoWidth = Set("Memowidth") && To restore previous setting lcProgramText = Filetostr(tcProgram) && Store the contents of tcProgram into lcProgramText lcNewProgramText = '' && Modified text llCommentCont = .f. && Flag to follow comments continuation llWasComment = .f. && Flag to indicate the line was a comment llCont = .f. && Flag to indicate that this line is continuation of the previous one set memowidth to 8192 && MemLines and MLine work with the current memo width set for i = 1 to Memlines(lcProgramText) lcRawLine = Mline(lcProgramText, i) && Original text lcLine = Alltrim(Strtran(lcRawLine, _TAB)) && Trimmed and _TAB stripped text lnPos = At(_DA, lcRawLine) && Position of double-ampersand comments do case case llCommentCont or (Left(lcLine, 1) = '*' and !llCont) && * comment start or continues lcNewLine = '' && Not really necessary, it can be handled with llRemove llWasComment = .T. && Next line is a comment too! llRemove = .T. && To avoid adding unnecessary empty lines case lnPos > 1 && There is a double-ampersand comment lcNewLine = Left(lcRawLine, lnPos - 1) && Remove it! llWasComment = .T. && This is to handle ; double ampersand comments that spans ; more than one line ; although they are not pretty! otherwise llWasComment = .F. && Regular line of code lcNewLine = lcRawLine && Just copy it endcase lcNewProgramText = lcNewProgramText + Iif(llRemove, '',Iif(Empty(lcNewProgramText), '', _CR) + lcNewLine) llRemove = .F. llCont = Right(lcLine, 1) = ';' && Next line is a continuation of this one llCommentCont = llCont and llWasComment && Next line is also a comment * This should handle lines starting with a * but as a result of an large formula, like: lnUnrelevantValue = (i + 1) ; * 5 && in here * 5 is definetely not a comment! next i set memowidth to (lnMemoWidth) && Restore the original Memowidth return lcNewProgramText && The comment-stripped version of the programThis is where I found my code, I think the OP made some changes to it that might be useful for you Newsgroup post