Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13899

Re: Swap lowercase and uppercase letters

From awnl <awnl@gmx-topmail.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Swap lowercase and uppercase letters
Date 2013-03-20 08:22 +0000
Message-ID <kibrke$14v$1@smc.vnet.net> (permalink)
References <ki6n3l$gee$1@smc.vnet.net> <ki8o4n$ko6$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


Hi,
>>
>> 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]
   }]

regards,

albert

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Swap lowercase and uppercase letters Bill <WDWNORWALK@aol.com> - 2013-03-18 09:34 +0000
  Re: Swap lowercase and uppercase letters Szabolcs <szhorvat@gmail.com> - 2013-03-19 04:04 +0000
    Re: Swap lowercase and uppercase letters awnl <awnl@gmx-topmail.de> - 2013-03-20 08:22 +0000

csiph-web