开发者

Nant reading file in reverse order

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜