{newb} file and puts

S

STEPHEN BECKER I V

f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file? i get
A

30
B

23
C

43
D

28
E

47
and i want
A 30
B 23
C 43
D 28
E 47

Becker
 
J

James Edward Gray II

f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file?


Use print() instead of puts() and insert \n characters as needed.

James Edward Gray II
 
J

Jason Voegele

James Edward Gray II said:
f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file?


Use print() instead of puts() and insert \n characters as needed.


Alternatively, continue to use puts() and use string variable
interpolation instead of separate parameters. In other words:

loc.puts("#{(i+65).chr} #{a}") if a>0

--
Jason Voegele
"There is an essential core at the center of each man and woman that
remains unaltered no matter how life's externals may be transformed
or recombined. But it's smaller than we think."
-- Gene Wolfe, The Book of the Long Sun
 
S

STEPHEN BECKER I V

Thank you so much! That kinda sucks when you need to output an int,
you need to remember the to_s
Thank you again
Becker


change last line:

loc.puts((i+65).chr+' '+a.to_s) if a>0

C

From: STEPHEN BECKER I V <[email protected]>
Date: Wed, 13 Oct 2004 04:45:34 +0900


f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file? i get
A

30
B

23
C

43
D

28
E

47
and i want
A 30
B 23
C 43
D 28
E 47

Becker

 
S

STEPHEN BECKER I V

Yes, i see there is always 6 ways to do the same thing... i think i
will be using print from now on.
Becker


f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file?


Use print() instead of puts() and insert \n characters as needed.

James Edward Gray II
 
J

James Edward Gray II

Thank you so much! That kinda sucks when you need to output an int,
you need to remember the to_s

You don't. Just use the interpolation technique that was suggested
with either puts() or print().

Hope that helps.

James Edward Gray II
 
A

Ara.T.Howard

f="z:\t.txt"
loc = File.open(f, "w+")
loc.puts((i+65).chr,' ',a) if a>0


loc.printf('%s %d', (i+65).chr, a) if a>0

Nevermind what it is writing, How do i keep the (i+65).chr and a on
the same line in the file? i get
A

30
B

23
C

43
D

28
E

47
and i want
A 30
B 23
C 43
D 28
E 47

Becker


kind regards.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top