开发者

Nant reading file in reverse order

开发者 https://www.devze.com 2022-12-11 16:07 出处:网络
I have a text file. I need to read开发者_JAVA百科 the content of the file from the reverse order (from EOF). Please let me know how I can achieve it using Nant script.

I have a text file. I need to read开发者_JAVA百科 the content of the file from the reverse order (from EOF). Please let me know how I can achieve it using Nant script.

Thanks, Priya.R


You could write it in C# inside your NAnt script like this:

<target name="read">
    <script language="C#" prefix="myprefix" >
        <code>
            <![CDATA[
                [Function("reverse-lines")]
                public static string ReverseLines( string s )
                {
                    string[] lines = s.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    string result = "";
                    foreach (string line in lines)
                    {
                        result = line + "\r\n" + result;
                    }

                    return result;
                }

            ]]>
        </code>
    </script>

    <loadfile file="myfile.txt" property="contents" />
    <echo message="File contents in correct order:" />
    <echo message="${contents}" />
    <echo message="File contents in reverse order:" />
    <echo message="${myprefix::reverse-lines(contents)}" />
</target>


You could use the Windows program sort /R to create a sorted copy of the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消