Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 18th, 2008, 10:27 AM
karym6 karym6 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Edinburgh, UK
Posts: 68 karym6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 27 m 23 sec
Reputation Power: 5
Send a message via MSN to karym6
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

Reply With Quote
  #2  
Old February 18th, 2008, 10:43 AM
karym6 karym6 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Edinburgh, UK
Posts: 68 karym6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 27 m 23 sec
Reputation Power: 5
Send a message via MSN to karym6
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:
Originally Posted by karym6
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

Reply With Quote
  #3  
Old February 19th, 2008, 12:27 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,394 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 8 h 36 m 18 sec
Reputation Power: 715
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

Reply With Quote
  #4  
Old February 19th, 2008, 02:06 PM
karym6 karym6 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Edinburgh, UK
Posts: 68 karym6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 27 m 23 sec
Reputation Power: 5
Send a message via MSN to karym6
Even more graceful - thanks

Quote:
Originally Posted by Scorpions4ever
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Printing double-quotes to files in Ruby


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway