Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Ruby support verbatim strings?

Is there support in Ruby for (for lack of a better word) non-escaped (verbatim) strings?

Like in C#:

@"c:\Program Files\"

...or in Tcl:

{c:\Program Files\}
like image 471
Cristian Diaconescu Avatar asked Oct 20 '08 12:10

Cristian Diaconescu


People also ask

How do you print a string in Ruby?

To display a string in your program, you can use the print method: print "Let's print out this string." The print method displays the string exactly as written. print 'This is the first string.

How do you create a string variable in Ruby?

Creating Strings: To create the string, just put the sequence of characters either in double quotes or single quotes. Also, the user can store the string into some variable. In Ruby, there is no need to specify the data type of the variable.


1 Answers

Yes, you need to prefix your string with % and then a single character delineating its type.

The one you want is %q{c:\program files\}.

The pickaxe book covers this nicely here, section is General Delimited Input.

like image 66
DevelopingChris Avatar answered Nov 06 '22 07:11

DevelopingChris