Re: [問題] 這樣的需求得要自己寫程式嗎?

看板Programming作者 (godfat 真常)時間16年前 (2007/09/26 18:40), 編輯推噓3(302)
留言5則, 5人參與, 最新討論串2/17 (看更多)
※ 引述《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
驚! Ruby..=.= Python啦... XDD
09/26 18:51, 1F

09/26 18:59, , 2F
我還沒什麼機會試玩 python :p
09/26 18:59, 2F

09/26 19:54, , 3F
來源檔案數字沒用\n隔開,是隨機出現的耶
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
文章代碼(AID): #16-ZSI81 (Programming)
討論串 (同標題文章)
文章代碼(AID): #16-ZSI81 (Programming)