vicky vicky - 6 months ago 8
Ruby Question

how to remove '\' from string

I am new to ruby.I have a string like

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."


and I want to remove "\" from whole string.

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."


How to make it possible.

Answer
>> 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."

Make sure you know what the difference between string representation (puts string.inspect) and string content (puts string) is, and note the backslashes as the artifacts of the representation.

Comments