MathGroup Archive 2013

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

Search the Archive

Re: Swap lowercase and uppercase letters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130208] Re: Swap lowercase and uppercase letters
  • From: awnl <awnl at gmx-topmail.de>
  • Date: Wed, 20 Mar 2013 04:22:38 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <ki6n3l$gee$1@smc.vnet.net> <ki8o4n$ko6$1@smc.vnet.net>

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



  • Prev by Date: Re: Swap lowercase and uppercase letters
  • Next by Date: rookie code issue
  • Previous by thread: Re: Swap lowercase and uppercase letters
  • Next by thread: OpenCL yes, Cuda no