• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Text - change case
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Text - change case


  • Subject: Re: Text - change case
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 19 May 2005 12:30:55 -0400



On 5/19/05, Steve Hayman <email@hidden> wrote:
Perl can be handy here if you can get past all the escape and
backslash quoting issues. It has a couple of operators that can
uppercase and lowercase strings - and a \u that says "uppercase one
character only."

So here is a possibility.  Pipe the text through a little perl script
that says, "for each word, convert the first character to upper case
and the rest to lower case."


set str to "APPLE COMPUTER"

-- I freely admit I did not get this right on the first try.
do shell script "echo " & quoted form of str & " |perl -p -e 's/(\\w
+)/\\u\\L$1/g;'"

There's no reason to go into $&-avoidance mode for this little one-liner; you can lose the parens.  And I don't like to use /'s as a delimiter when there are so many backslashes in there; makes it even harder to read.

do shell script "echo " & quoted form of str & " | perl -pe 's,\\w+,\\u\\L$&,g' "

On the command line or in a Perl script, that would just be s,\w+,\u\L$&,g  without the doubled backslashes.   In English: "Substitute (s,) every (,g) sequence of one or more (+) word characters (\w) by a copy of itself ($&) with all characters converted to lowercase (\L) and then the first character converted to uppercase (\u)."





_______________________________________________
Do not post admin requests to the list. They will be ignored. email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Text - change case (From: "Ruby Madraswala" <email@hidden>)
 >Re: Text - change case (From: Steve Hayman <email@hidden>)

  • Prev by Date: Re: Clear Metadata in Tiger
  • Next by Date: Re: Text - change case
  • Previous by thread: Re: Text - change case
  • Next by thread: Re: Text - change case
  • Index(es):
    • Date
    • Thread