Marketing_Insists
asked on
cases for multi-word strings
# Setting the case of a last name is done like so:
$last = ucfirst lc("sampson");
gives "Sampson"
# What about setting case for a multi-word string? e.g.;
$last = ucfirst lc("sampson-smith, jr");
gives Samson-smith, jr
But how can I get "Sampson-Smith, Jr" , where each portion of the proper name is capitalized?
$last = ucfirst lc("sampson");
gives "Sampson"
# What about setting case for a multi-word string? e.g.;
$last = ucfirst lc("sampson-smith, jr");
gives Samson-smith, jr
But how can I get "Sampson-Smith, Jr" , where each portion of the proper name is capitalized?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
First thing that comes to mind is something like this but it doesn't quite work...join '', map { ucfirst } split /(-|\s+)/, 'sampson-smith, jr';
$last = join ' ', map { ucfirst $_ } split /-,\s\s*/, 'sampson-smith, jr';
#or
join '', map { ucfirst } split /([-,\s])/, 'sampson-smith, jr';
#or
join '', map { ucfirst } split /(?<=-|\s)/, 'sampson-smith, jr';
#or
join '', map { ucfirst } split /(\W+)/, 'sampson-smith, jr';
#or
join '', map { ucfirst } split /\b/, 'sampson-smith, jr';
#might have worked
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
CPAN module may come in handy later with MacDonald vs Macer issues
CPAN module may come in handy later with MacDonald vs Macer issues
4) For simplicity, I would simply divide the points evenly between the four contributors since all four answered the question accurately:
http:#a38803391
http:#a38803401
http:#a38803612
http:#a38812799
http:#a38803391
http:#a38803401
http:#a38803612
http:#a38812799
\b = zero-width word-break assertion
\w+ = as many word characters as possible
flags:
g = repeat as many times as possible
e = execute the code in the rhs of the substitution