JScript replaceInFile

Author Johnny Josefsson on November 19, 2010 | Print | Bookmark
function replaceInFile( filename , searchForRx , replaceWith )
{
  filename = FormatArguments(filename , arguments); 
  
  if(typeof (searchForRx) == "string")
    searchForRx = FormatArguments(searchForRx , arguments); 
 
  replaceWith = FormatArguments( replaceWith , arguments ); 
 
  var text = ReadAll(filename); 
   // if(!searchForRx.exec(text) ) 
  
  text = text.replace(searchForRx,replaceWith); 
  
  WriteAll(filename, text); 
}

Was this article helpful?

Yes No

Category: Scripting, JScript

Last updated on May 15, 2011 with 1107 views