= Replace Text Example = ''Part of'' StandardLibraryCategory == Description == Take the input file and replace one string with another (repeatedly). == Example == {{{ #!d import std.stream; /* for File */ import std.string; /* for replace */ import std.stdio; /* for writefln */ void main(char[][] args) { char[] fromFileStr; char[] toFileStr; char[] fromStr; char[] toStr; char[] fileStr; char[] lnStr; if(args.length < 5) { writefln(`Usage: replace_text.exe fileIn fileOut "from" "to"` \n); return; } debug writefln("args.length: %s", args.length); debug for(int i = 0; i < args.length; i++) writefln("args[%s]: %s", i, args[i]); fromFileStr = args[1]; toFileStr = args[2]; fromStr = args[3]; toStr = args[4]; File inFile = new File(fromFileStr); while (!inFile.eof()) { lnStr = inFile.readLine(); debug writefln("%s", lnStr); fileStr ~= lnStr ~ \n; } inFile.close(); fileStr = replace(fileStr, fromStr, toStr); File outFile = new File(); with(outFile) { outFile.create(toFileStr); outFile.writeString(fileStr); outFile.close(); } return; } }}} == Batch File == {{{ @echo off dmd ReplaceTextExample.d ReplaceTextExample.exe ReplaceTextExample.exe "ReplaceTextExample.d" "ReplaceTextExampleX.d" "Str" "String" pause }}} == Compatibility Notes == Tested with Digital Mars D Compiler v0.162 on Windows 2000.