On Wed, Jun 6, 2012 at 10:28 PM, ideal one <lists / ruby-forum.com> wrote:
> Hi,
> =A0Following is my input:-
> Str =3D "This is a String."
>
> expected output is :-
> output =3D "4 2 1 7"
>
> I tried doing this but was not successful, any thoughts pls
>
> puts Str.count(" ").size =A0-> This doesn't fit my expected output.

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 =3D "this is a string."
 =3D> "this is a string."
1.9.2p290 :002 > s.split(" ").map {|x| x.length}.join(" ")
 =3D> "4 2 1 7"


Jesus.