RE: StringReplace and WordBoundary
- To: mathgroup at smc.vnet.net
- Subject: [mg67663] RE: [mg67635] StringReplace and WordBoundary
- From: "Ingolf Dahl" <ingolf.dahl at telia.com>
- Date: Tue, 4 Jul 2006 01:56:39 -0400 (EDT)
- Reply-to: <ingolf.dahl at telia.com>
- Sender: owner-wri-mathgroup at wolfram.com
Bruce, I think you should think of WordBoundary as an invisible "bar" between the space and the first letter. Try this string replacement: X="abba butter bbb a -+!test"; StringReplace[X, {Except[WordCharacter]...~~ WordBoundary~~y_-> ToUpperCase@y}] Use " "... instead of Except[WordCharacter]... if you only want to get rid of spaces and not other non-word characters. Best regards Ingolf Dahl -----Original Message----- From: Bruce Colletti [mailto:vze269bv at verizon.net] To: mathgroup at smc.vnet.net Subject: [mg67663] [mg67635] StringReplace and WordBoundary 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