2007年12月2日 星期日

Ruby 去標點字數統計程式

ca = File.new("a.txt", "r").read.split(//u)
sa = File.new("s.txt", "r").read.split(//u)
ic = ca.size
sa.each { |ssa|
ca.delete ssa
}
print ic-ca.size, " interpuctions deleted.\n"
print "Total ", ca.size, " words.\n"
==
a.txt:目標檔案(UTF-8編碼限定)
==
s.txt(UTF-8)
,。、「」:;  

==

ㄇㄉ這好威

沒有留言:

CODE { display: block; /* fixes a strange ie margin bug */ font-family: Courier New; font-size: 8pt; overflow:auto; background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y; border: 1px solid #ccc; padding: 10px 10px 10px 21px; max-height:200px; height:200px; // for IE6 line-height: 1.2em; } #quote { display: block; /* fixes a strange ie margin bug */ font-family: Verdana; font-size: 10pt; overflow:auto; background: #f7f7f7 url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKN19b4aT1DHj8GUNi63hQtkKMMZBz85Is4BxJdhPcfrcbaDczl_1lhtztSIirdEAoNLN5F-aDcr7pBSdyFbupvipv2q7vmWWhcqhgsf8nr_nH0jBKyn4YGlBfuiV-BOWA56z7mdE4XXo/s288/quote-l.gif) left top no-repeat; border: 4px dotted #ccc; padding: 15px 15px 15px 31px; /*up right bottom left*/ max-height:300px; line-height: 1.2em; }