顯示具有 ruby 標籤的文章。 顯示所有文章
顯示具有 ruby 標籤的文章。 顯示所有文章

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

2007年9月16日 星期日

Hello World!


  • Ruby

    puts "Hello World!"

  • jQuery
    $(document).ready(function(){$("p").append("Hello World!")}); 

  • JavaScript

    document.write("Hello World!")


  • C#

    using System;
    namespace HelloWorld {
    class Hello{
    static void Main(){
    System.Console.WriteLine("Hello World!");
    }
    }
    }

  • Java

    class HelloWorld{
    public static void main(String args[]){
    System.out.println("Hello World!");
    }
    }

  • Bash

    #!/bin/bash
    STR="Hello World!"
    echo $STR

  • HTML

    <html><head><title>Hello World</title></head><body><p>Hello World!</p></body></html>

  • C++

    #include <iostream.h>
    main(){
    cout << "Hello World!";
    return 0;
    }

  • C

    #include <stdio.h>
    main(){
    for(;;){
    printf ("Hello World!\n");
    }
    }