Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: changing case to Title Case [redux]
- X-seq: zsh-users 26779
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: TJ Luoma <luomat@xxxxxxxxx>
- Cc: Zsh MailingList <zsh-users@xxxxxxx>
- Subject: Re: changing case to Title Case [redux]
- Date: Sat, 19 Jun 2021 14:03:19 +0100
- Archived-at: <https://zsh.org/users/26779>
- In-reply-to: <CADjGqHusQwz=W+Qht1pAd-wYqe5A1tArav=XSBZ=fNyq4o1SNA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: TJ Luoma <luomat@xxxxxxxxx>, Zsh MailingList <zsh-users@xxxxxxx>
- References: <CADjGqHusQwz=W+Qht1pAd-wYqe5A1tArav=XSBZ=fNyq4o1SNA@mail.gmail.com>
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