|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Printing double-quotes to files in Ruby
Hi All,
I had a brilliant thought this morning, why not use ruby to generate some xml for me. Was a great idea, but I have fallen flat on my face when it comes to adding " to my xml file. I am trying to create this line: puts results_file.puts "<component timestamp="" name=""#{x}"" />" But, my issue is that it is giving me: <component timestamp= name=some_name.dll /> as you can probably tell, this doesnt look good. Could some kind soul let me know how to put the " char correctly into my output please? Cheers - Karym6 |
|
#2
|
|||
|
|||
|
and I figured it out by using \" to include them in the file making my code look like:
puts results_file.puts "<component timestamp=\"\" name=\"#{x}\" /> Quote:
|
|
#3
|
||||
|
||||
|
Alternatively, you could enclose your string in %Q{}
Code:
#!/usr/bin/ruby
x = "hello"
f = File.open("file.txt", "w")
f.puts %Q{<component timestamp="" name="#{x}" />}
f.close()
Note that %q won't substitute #{x} and will leave it in literally, whereas %Q will interpolate the variable.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#4
|
|||
|
|||
|
Even more graceful - thanks
![]() Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Printing double-quotes to files in Ruby |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|