Comment detail
条件を満たす行を取り除く (Nested Flatten)
まんまF#でやってみました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | open System;;
open System.Text;;
open System.IO;;
open Array;;
let fileIO (ifname:string) (ofname:string) =
let streamW = new StreamWriter( ofname, false, Encoding.Default ) in
let streamR = new StreamReader( ifname, Encoding.Default ) in
let rmCommentLn (wstream:StreamWriter) =
let rec readf (rstream:StreamReader) =
let line = rstream.ReadLine() in
if line = null then ()
else
begin
if not (line.StartsWith "#")
then wstream.WriteLine line
else ();
readf rstream
end
in using streamR readf
in using streamW rmCommentLn;;
if (length Sys.argv) = 3
then fileIO Sys.argv.(1) Sys.argv.(2)
else ();;
|
usingは多段重ねできるんですね(^^; http://www.divakk.co.jp/aoyagi/csharp_tips_using.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | using System;
using System.Collections.Generic;
using System.Text;
namespace FileIO
{
class Program
{
static void Main(string[] args)
{
FileIO("sample_in.txt", "sample_out.txt");
}
static void FileIO(string fnameIn, string fnameOut)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fnameOut,false,System.Text.Encoding.Default))
using (System.IO.StreamReader sr = new System.IO.StreamReader(fnameIn, System.Text.Encoding.Default))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (!line.StartsWith("#"))
{
sw.WriteLine(line);
}
}
}
}
}
}
|





PoohKid
#563()
[
C#
]
Rating1/1=1.00
Rating1/1=1.00-0+
2 replies [ reply ]