2008年7月22日 星期二

從文字檔讀入並讀出特定字串那行

只做簡單的比對,若要變更只要更改正規式裡面的條件就好

不過應該有比較簡易的寫法吧?目前是這樣比較容易閱讀 :p

filename = 'input.txt'
output = 'output.txt'

if File.file? filename
  p 'Reading File...'
  open(filename) do |f|
    open(output, 'a') do |out|  
  p 'Writting File...'
      f.to_a.each do |x|
        if x =~ /String!/
          out.puts x
        end
      end

    end # end of output   
  end # end of filename

else
  p "File Open Error!"
end

http://pastie.org/238588

2008年7月2日 星期三

C# Error CS1501

寫C#的時候發現這個錯誤,原因是我使用了繼承了某個建構子有設定值的類別。

後來在這邊翻到,原來有建構子有設定值傳入的話,要再後面加上: base(Object o)這樣的結構。

這樣的寫法我好像在C++看過,可能是我C++還不夠熟的關係吧 XD

class Base
{
    public Base(string s)
    {
    }
}

class Derived : Base   
{ // CS1501
    public Derived(string s) : base(s)
    {
    }
}