Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Swap lowercase and uppercase letters
Replies: 2   Last Post: Mar 20, 2013 4:22 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Albert Retey

Posts: 688
Registered: 7/15/08
Re: Swap lowercase and uppercase letters
Posted: Mar 20, 2013 4:22 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

>> I have the following example: "hELLO THERE!"
>> Using Mathematica 8.0.4, how can I swap the lowercase and uppercase
>> letters to output,
>> "Hello there!"

> This is a reliable method that will work with scripts other than
> Roman (such as Greek or Cyrillic) and will also work with many
> accented letter:
> StringJoin@ Replace[Characters["hELLO THERE!"], {c_?LowerCaseQ :>
> ToUpperCase[c], c_?UpperCaseQ :> ToLowerCase[c]}, {1}]
> Simply replacing A, B, ..., Z with a, b, ..., z is not a good option
> because it won't handle accented letters (unless you include those as
> well, which is a lot of work)

or, slightly simpler:

StringReplace["hELLO THERE!", {
c_?UpperCaseQ :> ToLowerCase[c],
c_?LowerCaseQ :> ToUpperCase[c]



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.