Back

ReplaceInFile

Hello World

Replaces all occurances of some text or a regex pattern in a local file with some other text.

app.ReplaceInFile( file, txt, rep, options )

Example - Replace Text in File

function OnStart()
{
    app.WriteFile( "file.txt", "Hello world, exciting world." );
    app.ReplaceInFile( "file.txt", "world", "user" );
    app.Alert( app.ReadFile( "file.txt" ), "Result" );
}
    Copy     Copy All       Run      

Example - Replace Regular Expression

function OnStart()
{
    app.WriteFile( "file.txt", "Hello world, exciting world." );
    app.ReplaceInFile( "file.txt", "(\\w+)o (\\w+)", "$2 is $1" );
    app.Alert( app.ReadFile( "file.txt" ), "Result" );
}
    Copy     Copy All       Run      
string
string: comma “,” separated
string: path to file or folder ( “/absolute/...” or “relative/...” )