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: [mg130196] Re: Swap lowercase and uppercase letters
  • From: Szabolcs <szhorvat at gmail.com>
  • Date: Tue, 19 Mar 2013 00:05:41 -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>

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)



  • Prev by Date: Re: CAPopup|c|228 internal self-test errors
  • Next by Date: Re: Cropping image parts through list of lists
  • Previous by thread: Re: Swap lowercase and uppercase letters
  • Next by thread: Re: Swap lowercase and uppercase letters