Clean a header

Hi, I’ve a string like this:

header = “Header : \r\n \t \r\n \t 111 aaa 2222 3333 \r\n”

I need to clean it and leave as follows:

“Header:111 aaa 2222 3333”

The best I get is this:

header.strip.gsub(/(\s*)/,"")
=> “Header:111aaa22223333”

Obviously this is not valid since it “eats” the spaces into the header
body. How could I fix it?

Thanks in advance.

On Mar 25, 2008, at 1:51 PM, Iñaki Baz C. wrote:

header.strip.gsub(/(\s*)/,“”)
=> “Header:111aaa22223333”

Obviously this is not valid since it “eats” the spaces into the header
body. How could I fix it?

Thanks in advance.

Iñaki Baz C.
[email protected]

irb> header = “Header : \r\n \t \r\n \t 111 aaa 2222 3333
\r\n”
=> “Header : \r\n \t \r\n \t 111 aaa 2222 3333 \r\n”
irb> header.strip.sub(/\s*:\s*/,‘:’).gsub(/\s+/,’ ')
=> “Header:111 aaa 2222 3333”

Good enough?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

El Martes, 25 de Marzo de 2008, Rob B.
escribió:

irb> header = “Header : \r\n \t \r\n \t 111 aaa 2222 3333
\r\n”
=> “Header : \r\n \t \r\n \t 111 aaa 2222 3333 \r\n”
irb> header.strip.sub(/\s*:\s*/,’:’).gsub(/\s+/,’ ')
=> “Header:111 aaa 2222 3333”

Good enough?

No good, it’s fantastic :slight_smile:

Thanks a lot.