我是ruby的新手。我有一个像
这样的字符串string = "You have successfully placed Service Request No. \#{@service_requests.id} for \#{@service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
我想删除" \"从整个字符串。
output_string = "You have successfully placed Service Request No. #{@service_requests.id} for #{@service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
如何使它成为可能。
答案 0 :(得分:3)
试试这个:
string.gsub(/\\/, '') # or string.gsub!(/\\/, '') for inplace substitution
答案 1 :(得分:3)
>> string = "You have successfully placed Service Request No. \#{@service_requests.id} for \#{@service_requests.category.name} . Our representative will be in touch with you soon for
the same. Thank you."
>> puts(string)
=> You have successfully placed Service Request No. #{@service_requests.id} for #{@service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you.
>> puts(string.inspect)
=> "You have successfully placed Service Request No. \#{@service_requests.id} for \#{@service_requests.category.name} . Our representative will be in touch with you soon for the same. Thank you."
确保您知道字符串表示(puts string.inspect
)和字符串内容(puts string
)之间的区别,并注意反斜杠作为表示的工件。
答案 2 :(得分:0)
您可以将其删除,如:
string.gsub(%r{\"}, '')