Re: StringReplace and WordBoundary
- To: mathgroup at smc.vnet.net
- Subject: [mg67691] Re: [mg67635] StringReplace and WordBoundary
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Wed, 5 Jul 2006 04:17:03 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
X="abba butter bbb a"; StringJoin[StringSplit[ StringReplace[X,WordBoundary~~y_->ToUpperCase@y]]] AbbaButterBbbA StringReplace[ StringReplace[X,WordBoundary~~y_->ToUpperCase@y], Whitespace->""] AbbaButterBbbA StringReplace[X,{ WordBoundary~~x:WordCharacter->ToUpperCase[x], Whitespace->""}] AbbaButterBbbA %==%%==%%% True Bob Hanlon ---- Bruce Colletti <vze269bv at verizon.net> wrote: > Re v5.2.0.0. > > This code capitalizes each word's first letter: > > X="abba butter bbb a"; > StringReplace[X,WordBoundary~~y_->ToUpperCase@y] > > "Abba Butter Bbb A" > > However, I mistakenly thought StringReplace would substitute the full "WordBoundary~~y_" pattern by a capital letter to give "AbbaButterBbbA". How do I change the code to do this? > > The StringReplace help text says "replaces every SUBSTRING that matches lhs." Is it this focus upon the substring that explains why the above code leaves WordBoundary untouched? Or is the "real" reason something else? > > Thanks. > > Bruce >