Upper and Lower Case Conversion


One of those pieces of "boiler-plate" requirements that goes into many applications, here's a traditional lower-case converter presented as a Dyalog d-fn...

     lcase←{                                         ⍝ Lower-casification,
       lc←'abcdefghijklmnopqrstuvwxyzåäöàæéñøü'    ⍝ (lower case alphabet)
       uc←'ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖÀÆÉÑØÜ'    ⍝ (upper case alphabet)
       (lc,⎕AV)[(uc,⎕AV)⍳⍵]                        ⍝ ... of simple array.
     }

The advent of Unicode means that the above isn't necessarily universally useable, and an alternative uses Microsoft .NET (in the same way that might be done from other languages)...

         ToLower←{⎕USING←''  
  ⍝ Lower-case conversion using .NET (from Morten Kromberg)
       (⍴⍵)⍴(⎕NEW System.String(⊂,⍵)).ToLower ⍬}

And, as a nicety when handling names we need something to handle the common prefixes...

  capword←{⎕ML←3
          z←(ucase↑⍵),lcase 1↓⍵
          (⊂2↑z)∊'Mc' 'O''r':(2↑z),(ucase↑2↓z),3↓z
          z}

Notes:
Page created 23 March 2009.
Copyright © Dogon Research 2009.