the12 the12 - 1 year ago 104
Ruby Question

Spaces in string vs. Escape sequences

In Ruby (testing in the Interactive Ruby Shell), you can either use spaces in strings or use escape sequences. Is there a best practice in determining which to use, or does it never matter?

For example:

"Hello World"

--> "Hello World"



--> "Hello World"

Answer Source

Use spaces. Makes it much more easier to read

If you cant, then use the escape sequences.

Also note that escape only works in double quotes

    --> 'Hello\\sWorld'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download