MathGroup Archive 2006

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

Search the Archive

Re: StringReplace and WordBoundary

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67659] Re: StringReplace and WordBoundary
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 4 Jul 2006 01:56:26 -0400 (EDT)
  • References: <e8as9s$g6k$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Bruce,
a WordBoundary is a zero width marker just before or after any word. It 
is NOT a WhiteSpace! Threfore what you want is:
Whitespace ~~ y_
however, this does not capitalize the first character. For this we need 
your old:
WordBoundary ~~ y_
both together:
(Whitespace | WordBoundary) ~~ y_

Daniel

Bruce Colletti 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
> 


  • Prev by Date: RE:For loop and dynamic Table
  • Next by Date: Re: Position
  • Previous by thread: StringReplace and WordBoundary
  • Next by thread: Re: StringReplace and WordBoundary