[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] how to change the first character into upper case



On 22/02/12 05:23, David Christensen wrote:
On 02/21/2012 07:48 AM, lina wrote:
Sorry a bit off-topic, but I am stuck with how to tr
(googled some ways out, still not work)

NELSON ARISPE, EDUARDO ROJAS, AND HARVEY B. POLLARD

into

Nelson Arispe, Eduardo Rojas, and Harvey B. Pollard

I'd use Perl and the Lingua::EN::Titlecase module:


http://search.cpan.org/~ashley/Lingua-EN-Titlecase-0.14/lib/Lingua/EN/Titlecase.pm

For example:

2012-02-21 20:04:27 dpchrist@p43400e ~
$ echo "NELSON ARISPE, EDUARDO ROJAS, AND HARVEY B. POLLARD" | perl -MLingua::EN::Titlecase -ne '$tc = Lingua::EN::Titlecase->new($_); print $tc->title'
Nelson Arispe, Eduardo Rojas, and Harvey B. Pollard
Or Python which has a capitalize() function built-in (for you long-one-liner lovers - i.e. this is bad, unreadable code :)

~$ python -c "print (' '.join([str.capitalize(x) for x in 'NELSON ARISPE, EDUARDO ROJAS, AND HARVEY B. POLLARD'.split(' ')]))"
Nelson Arispe, Eduardo Rojas, And Harvey B. Pollard

Lorenzo.


HTH,

David





Reply to: