[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Force newline only on Windows

Steve V

4/12/2005 5:54:00 AM

How can I force \n in my strings to be *only* a newline character and not a
carriage return/newline combination on Windows?

Thanks,
Steve




3 Answers

Shajith

4/12/2005 6:11:00 AM

0

Hi 'talk!

Is there anything in Rubyland like SciPy?

URL: http://www.scipy....

In short, it is a collection of scientific tools, combining a lot of
numeric functions, data visualization/plotting routines etc into a
single package. (The part I liked was about how it can transform the
Python command line interpreter to a very capable Math/Analysis tool)

Does any combination of Ruby libraries offer the same sort of functionality?

Thanks in advance!
Shajith

PS: Apologies if this sounds like another of those "Ruby vs Python" things.

PS1: Right now, I am aware of Narray. I'm also looking for some more
functionality(optimization?, plotting, etc)


Robert Klemme

4/12/2005 7:17:00 AM

0


"Steve V" <ruby@digitalnothing.com> schrieb im Newsbeitrag
news:LDEHKBBOEMIJKHKBOFNFCEHPNBAA.ruby@digitalnothing.com...
> How can I force \n in my strings to be *only* a newline character and
not a
> carriage return/newline combination on Windows?

It's always just a newline in strings. I guess you mean you want the \n
in a file written:

09:14:10 [temp]: irb
irb(main):001:0> File.open("x","wb") {|io| io.puts "foo\nbar"}
=> nil
irb(main):002:0> exit
09:15:51 [temp]: od -t c x
0000000 f o o \n b a r \n
0000010
09:15:56 [temp]:

Kind regards

robert

Glenn Parker

4/12/2005 1:48:00 PM

0

Steve V wrote:
> How can I force \n in my strings to be *only* a newline character and not a
> carriage return/newline combination on Windows?

Use "binary" mode when opening your file, or invoke the "binmode" method
on your IO object.

File.open("x.txt", "wb") do |file|
file.print "\n"
end

On Windows, x.txt will contain only "\n". If you leave out the "b", you
will get "\r\n" instead.

STDOUT.binmode
print "\n"

This will make the same change to stdout.

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoi...