Re: [問題] 這樣的需求得要自己寫程式嗎?
※ 引述《buniro (期待2008!)》之銘言:
: 有一個2MB多的Unicode純文字檔,當中有很多重覆的字串"1"、"2"、"3"..."200",
: 如果想將"85"之後的字串其數值都+1,也就是處理後"1"~"84"不變,"85"變"86"、
: "86"變"87"...."200"變"201",那麼這有什麼現成的Editor可以使用嗎?還是非得
: 自己寫個程式來處理?
對 programmer 來說這很簡單,寫程式不見得會比用 editor 慢
: 如果只能自己寫的話,各位板友建議用哪一種語言寫,對初學者來說比較容易?
建議用 Ruby XD
歡迎到 ptt Ruby 板參觀 XD
: 處理速度又以哪一種語言最快呢?還是速度都差不多?
C/C++ 和 Objective-Caml 都很快,不過你的問題應該不用考慮這個。
如果你的檔案是 2GB 的話可以再來考慮看看。
假設你的文字檔是 utf-8, 數字用 \n 隔開:
*
$KCODE = 'u' # 設定使用 utf-8, 不過純數字的話是不是 utf-8 根本沒差
File.open("你的檔案", "r"){ |input|
File.open("目標檔案", "w"){ |output|
output << input.read.split("\n").map{ |line|
# 將文字讀入記憶體,用 \n 分開存成 array, 並使每一行變成...
line.to_i >= 85 ? (line.to_i+1).to_s : line
# 如果轉成數字的字串大於等於 85, 則加一後轉回字串,否則不動
}.join("\n")
# 把 \n 斷行存回去
}
}
--
#!/usr/bin/ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》
# if a dog nailed extra legs that http://www.ptt.cc/bbs/Ruby/index.html
# walks like an octopus, and Welcome ~Ruby@ptt~
# talks like an octopus, then ◢█◣ http://www.ruby-lang.org/
# we are happy to treat it as █ http://www.ruby-doc.org/
# if it were an octopus. ◥ ◤ http://www.rubyforge.org/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.132.59.20
推
09/26 18:51, , 1F
09/26 18:51, 1F
→
09/26 18:59, , 2F
09/26 18:59, 2F
推
09/26 19:54, , 3F
09/26 19:54, 3F
→
09/26 21:52, , 4F
09/26 21:52, 4F
推
09/27 15:12, , 5F
09/27 15:12, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 17 篇):