[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to find carriage-return characters

Bill Walker

4/17/2008 3:17:00 PM

I need to do a .gsub or .split or the equivalent to locate carriage-return
characters =AD Hex 0d . How can I do this in ruby? Thanks. Bill Walker

2 Answers

Sean O'Halpin

4/17/2008 4:25:00 PM

0

On Thu, Apr 17, 2008 at 4:16 PM, Bill Walker <Bill@walker-vt.us> wrote:
> I need to do a .gsub or .split or the equivalent to locate carriage-retur=
n
> characters =AD Hex 0d . How can I do this in ruby? Thanks. Bill Walke=
r
>

irb --> puts "hello\x0d".gsub(/\x0d/, '!')
hello!

Regards,
Sean

Peña, Botp

4/18/2008 2:43:00 AM

0

From: Bill Walker [mailto:Bill@Walker-VT.us]=20
# I need to do a .gsub or .split or the equivalent to locate=20
# carriage-return characters =AD Hex 0d .

CR is represented as "\r"

0x0d.chr
#=3D> "\r"

so,

"test\rx".gsub(/\r/){"[]"}
#=3D> "test[]x"

"test\rx asdfa\rasdf".split(/\r/)
#=3D> ["test", "x asdfa", "asdf"]