Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: changing case to Title Case [redux]



2021-06-19 08:20:07 +0200, TJ Luoma:
[...]
> > > $ foo="ONE TWO thRee FoUR"
> > > $ print -r -- "${(C)foo}"
> > >
> > > will output this:
> > >
> > > One Two Three Four
> > >
> > > but this:
> > >
> > > $ foo="ONE TWO thRee FoUR's"
> > > $ print -r -- "${(C)foo}"
> > >
> > > will give this:
> > >
> > > One Two Three Four'S
> > >
> > > Note the S is capitalized
[...]

To change to title case all sequences of 2 or more letters (and
to lowercase the isolated letters), you can always do:

set -o extendedglob # for (#m), (#c)
print -r - ${${@:l}//(#m)[[:alpha:]](#c2,)/${(C)MATCH}}

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author