C
Carlos Ortega
Hello Folks with a question I would like someone can clarify me:
When I type the following code:
"Substring1 Substring2 Substring3".each( '\s*' ) { | substring |
puts "[" + substring +"]"
}
What I got is:
[Substring1 ]
[Substring2 ]
[Substring3]
However when I type:
"Substring1 Substring2 Substring3".each( '\s*' ) { | substring |
puts "[" + substring +"]"
}
What I got is:
[Substring1 Substring2 Substring3]
Why the difference in outputs?
I verified in the "Programming Ruby 2nd (Dave Thomas - 2005)"
and it says that the ' ' is just one of the White Characters
that '\s' may represent ( the other ones are TAB and NEW LINE)
Any help would be very appreciated.
When I type the following code:
"Substring1 Substring2 Substring3".each( '\s*' ) { | substring |
puts "[" + substring +"]"
}
What I got is:
[Substring1 ]
[Substring2 ]
[Substring3]
However when I type:
"Substring1 Substring2 Substring3".each( '\s*' ) { | substring |
puts "[" + substring +"]"
}
What I got is:
[Substring1 Substring2 Substring3]
Why the difference in outputs?
I verified in the "Programming Ruby 2nd (Dave Thomas - 2005)"
and it says that the ' ' is just one of the White Characters
that '\s' may represent ( the other ones are TAB and NEW LINE)
Any help would be very appreciated.