Thanks paul. I already have this type of thing in a compiled form. Perhaps a script form will be less scary for clients?

 

steve

 


From: Paul Cowan [mailto:[EMAIL PROTECTED]
Sent: Friday, July 29, 2005 10:43 AM
To: Steve Baker; [email protected]
Subject: RE: [Nant-users] regex replace

 

The following target maybe of use to you.

     

<target name="fixCssReferences">

            <foreach item="File" property="filename">

                  <in>

                        <items>

                              <include name="**/*.css"/>

                        </items>

                  </in>

                  <do>

                        <echo message="${filename}"/>

                        <property name="cssFileName" value="${filename}"/>

                        <property name="find1" value="/vor/vor.site/"/>

                        <property name="replace1" value="/volvooceanrace/"/>

                        <property name="find2" value="/vor/vor.cms/"/>

                        <property name="replace2" value="/vorcms/"/>

                        <script language="C#">

                              <imports>

                                    <import namespace="System.Text.RegularExpressions"/>

                                    <import namespace="System.IO"/>

                              </imports>

                              <code><![CDATA[

                              public static void ScriptMain(Project project) {

                                    StreamReader reader = File.OpenText(project.Properties["cssFileName"]);//${filename});

                                    string file = String.Empty;

                                    try {

                                          Regex expression1 = new Regex(project.Properties["find1"]);

                                          Regex expression2 = new Regex(project.Properties["find2"]);

                                          file = reader.ReadToEnd();

                                          file = expression1.Replace(file, project.Properties["replace1"]);

                                          file = expression2.Replace(file, project.Properties["replace2"]);

                                    } finally {

                                          // must remember to close the file or the compile may not work

                                          reader.Close();

                                    }

                                    // create a writer and open the file

                                    TextWriter tw = new StreamWriter(project.Properties["cssFileName"]);//${filename});

                                    try {

                                          // write a line of text to the file

                                          tw.WriteLine(file);

                                    } finally {

                                          // close the stream

                                          tw.Close();

                                    }

                              }

                              ]]></code>

                        </script>

                  </do>

            </foreach>

      </target>

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Steve Baker
Sent: 29 July 2005 16:34
To: [email protected]
Subject: [Nant-users] regex replace

 

I don’t see any type of functionality in nant or nantcontrib to find and replace a string value in a file.

 

There is xmlpoke for xml files. How are people doing the same type of thing for non xml files?

 

I wrote a task for this myself a while back, but sometimes clients prefer to use only publicly supported tasks.

 

It went something like this:

 

<regex-replace file=”filepath” find=”regex _expression_” replace=”replace value” casesensitive=”true” />

 

Am I missing something that exists in nant or contrib itself? Why wouldn’t something like this be included?

 

Thanks,

 

steve

 

 


_____________________________________________________________________
VirusChecked for Huntsworth plc
_____________________________________________________________________


_____________________________________________________________________
VirusChecked for Huntsworth plc
_____________________________________________________________________

Reply via email to