The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Swap lowercase and uppercase letters
Replies: 5   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 ]
Bill Rowe

Posts: 1,647
Registered: 3/14/08
Re: Swap lowercase and uppercase letters
Posted: Mar 19, 2013 1:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 3/18/13 at 5:35 AM, (Bill) wrote:


>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!"

Although this isn't truly a swap of lowercase and uppercase, the
result is what you are asking for

In[2]:= ToUpperCase[StringTake[#, 1]] <>
ToLowerCase[StringDrop[#, 1]] &["hELLO THERE!"]

Out[2]= Hello there!

If you want to do a litteral swamp of lower case and upper case
you could first convert the string to character codes then add
32 if the character code was between 65 ("A") and 90 ("Z") or
subtract 32 if the character code was between 97 ("a") and 122
("z") the use FromCharacter code and StringJoin to re-assemble
the string.

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.