How to find carriage-return characters

B

Bill Walker

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
 
S

Sean O'Halpin

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
 
P

Peña, Botp

From: Bill Walker [mailto:[email protected]]=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"]
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top