PHP 程式 學習 筆記本
個人學習程式與網路收集資料BLOG,期待與大家教學相長... 「設計的核心是溝通」 「溝通的核心是故事」
2012年5月30日 星期三
Replace ' with \' in Ruby? 如何將’ 轉換成 \' ?
"'".gsub("'","\\'")
原則上 \' 要換成 \\' 才可以.
答案:
puts "'".gsub("'","\\\\'")
若是使用 \\' 去置換, 他會把 a 後面的字元 , replace 一次.
"abcd".gsub("a","\\'")
=> "bcdbcd"
【下列文章您可能也有興趣】
>>>Ruby on Rails
[Rails Error] rubygems/core_ext/kernel_require.rb in `require': cannot load such file -- bundler/setup (LoadError)
[Rails] 運用 Net::HTTP and URI
[Rails] require: cannot load such file -- bundler/setup (LoadError)
Ruby &block lambda proc yield 使用
[Rails] ActiveRecord::Enum
Rails 4 class method 使用 alias_attribute, alias_method_chain, delegate, mattr_accessor
An ActionDispatch::RemoteIp::IpSpoofAttackError 10.xx.xx.xx
Rails 3.2.20 redirecting class 內的 _compute_redirect_to_location
Devise Issue: “[17] is not a symbol” [duplicate]
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言