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

Re: changing case to Title Case



On Mon, 14 May 2012 15:30:49 -0400
TJ Luoma <luomat@xxxxxxxxx> wrote:
> $ 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

If you like squiggles, you could do this:

print -r -- ${${(L)foo}//(#b)((#s)|[[:space:]])([[:alpha:]])/$match[1]${(U)match[2]}}

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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