Build better and engage your customers across all channels with our API reference documentation, quickstarts, SDKs and multi-language code samples.
文字列の置換には、sub、sub!、gsub、gsub!メソッドを使う string#sub(置換前パターン,置換後文字列) subは最初のパターンだけを置換。gsubは全てのパターンを置換する。 !をつけると、元のインスタンスの内容を変更する。 サンプル open("hoge.txt"){ |f| open("out.txt","w"){ |o| while line = f.gets line.gsub!("foo","bar") o.puts line end } }open("out2.txt","w"){ |o| open("hoge.txt").each{ |line| o.puts line.gsub("foo","bar") } } ワンライナーでも可能 ruby -e 'puts File.read("in.txt").gsub(/foo/,"bar")' > out.t
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く