From: gabriele renzi Date: 2004-03-28T00:29:24+09:00 Subject: Re: Formatting dates and counting words il Sun, 28 Mar 2004 03:07:44 +1200, "Robo" ha scritto:: >Hi, > >Just got started on making a real attempt in building a Ruby app, and got >some basic questions: > >How do I format a date? E.g. something like PHP's date() function where it >can show a date as a string in various formats: I believe Time#strftime() is what you need >http://www.php.net/manual/en/function.date.php > >Secondly, given a string, how do I get the first few words from it? e.g. If >a string has 50 words, I want the first 10 words return. please define what "word" means. usually this could work: >> s="this is a string of \n7 words" => "this is \ta string of \n7 words" >> ary=s.split(/\s+/) => ["this", "is", "a", "string", "of", "7", "words"] >> ary[0..2] => ["this", "is", "a"] Or you could use \W+ or [a-z]+ or..