You can split with Str.split(" "), which will return an array of strings.
Iterate through the array counting the length of the individual
strings, then join the resulting numbers using Array#join:
1.9.2p290 :001 > s = "this is a string."
=> "this is a string."
1.9.2p290 :002 > s.split(" ").map {|x| x.length}.join(" ")
=> "4 2 1 7"
Jesus.
···
On Wed, Jun 6, 2012 at 10:28 PM, ideal one <lists@ruby-forum.com> wrote:
Hi,
Following is my input:-
Str = "This is a String."
expected output is :-
output = "4 2 1 7"
I tried doing this but was not successful, any thoughts pls
puts Str.count(" ").size -> This doesn't fit my expected output.