// -*- ASCII:EDT -*- // envReplace.edt // (schlicht 20010517) // replaces a string only // in specifiable Environments ////////////////////////////// // You don't have to specify the environment every time: LetReg(3,"%$('envReplace');"); // The environment string has to be put in terms of // WinEdt's Regular expressions. // That is, the characters // $, \, <, >, [, ], {, }, ?, ., *, +, @, ~, |, ^ // have to preceded by a \, if you want them to have // their literal meaning. EnterReg(3,"...using Regular Expressions, f.i. ""\$*\$"" or ""\\\[*\\\]""",> "Specify Environment..."); Assign("envReplace","%!3"); // The find and replace strings are *not* Regular Expressions. // (We would have problems with the lengths.) EnterReg(6,"String to be replaced:","Replace in %$('envReplace');"); EnterReg(7,"... with:","Replace in %$('envReplace');"); GetLength(8,"%!6"); GetLength(9,"%!7"); LetRegNum(9,"%!9-%!8"); CMD("Select All"); GetSel(1,5); FindInString("%!5","%$('envReplace');",3,4,0011,0); IfOK("","Prompt('Environment not found.',2,1);"); LetRegNum(4,-1); BeginGroup; Loop(> !`SetOK(1);> FindInString("%!5","%$('envReplace');",3,4,1011,%!4+1);> IfOK(> !"ExtractByIndex(0,'%!5',%!3,%!4);> LetRegNum(2,0);> LetRegNum(8,0);> Loop(> !'SetOK(1);> FindInString(''%!0'',''%!6'',1,2,1010,%!2);> IfOK(> !''ReplaceInString(|%!0|, |%!7|,%!1,%!2,0,0);> LetRegNum(2,|%!2+(%!9)+1|);> LetRegNum(8,|%!8+(%!9)|);'',> ''Stop;'');> ');> ReplaceInString('%!5','%!0',%!3,%!4,0,5); > LetRegNum(4,'%!4+(%!8)');> ",> "Stop;");> `); CMD("Delete"); Ins('%!5');> EndGroup; Prompt("Another one?",1,3,"Exe('envReplace.edt');"); End; //////////////////////////////// // R Schlicht w.m.l@gmx.net // ////////////////////////////////