MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

StringReplace and WordBoundary

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67635] StringReplace and WordBoundary
  • From: Bruce Colletti <vze269bv at verizon.net>
  • Date: Mon, 3 Jul 2006 06:37:35 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: finite differencing of a PDE system
  • Next by Date: Re: ReadList[file,HeldExpression] ?
  • Previous by thread: Re: Position
  • Next by thread: Re: StringReplace and WordBoundary