in reply to Format question
#!/usr/bin/perl use strict; use warnings; print ToTitleCase('barney rubble'); exit; ############################################ # v2019.12.4 # Capitalizes the first letter of every word, # and returns a new string. # Usage: STRING = ToTitleCase(STRING) # sub ToTitleCase { my $S = defined $_[0] ? lc($_[0]) : ''; my ($i, $p, $BREAK) = (-1, 0); while (++$i < length($S)) { ($BREAK = index(" .,:;!?/\\()[]{}<>|-+=\t\n\r\xFF", substr($S, $i, + 1))) >= 0 or $p < 0 or ($p = vec($S, $i, 8)) > 122 or vec($S, $i, 8) = $p & 223; $p = $BREAK; } return $S; } ############################################
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Format question (capitalization)
by hippo (Archbishop) on Dec 05, 2019 at 15:16 UTC | |
Re^2: Format question
by Your Mother (Archbishop) on Dec 05, 2019 at 15:37 UTC |