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


Groups > comp.soft-sys.math.mathematica > #13881 > unrolled thread

Swap lowercase and uppercase letters

Started byBill <WDWNORWALK@aol.com>
First post2013-03-18 09:34 +0000
Last post2013-03-20 08:22 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  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

#13881 — Swap lowercase and uppercase letters

FromBill <WDWNORWALK@aol.com>
Date2013-03-18 09:34 +0000
SubjectSwap lowercase and uppercase letters
Message-ID<ki6n3l$gee$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!"


Thanks,

Bill

[toc] | [next] | [standalone]


#13885

FromSzabolcs <szhorvat@gmail.com>
Date2013-03-19 04:04 +0000
Message-ID<ki8o4n$ko6$1@smc.vnet.net>
In reply to#13881
On Monday, 18 March 2013 05:34:45 UTC-4, Bill  wrote:
> 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)

[toc] | [prev] | [next] | [standalone]


#13899

Fromawnl <awnl@gmx-topmail.de>
Date2013-03-20 08:22 +0000
Message-ID<kibrke$14v$1@smc.vnet.net>
In reply to#13885
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web