Path: utzoo!yunexus!ists!jarvis.csri.toronto.edu!rutgers!njin!princeton!siemens!jaguar!balcer From: balcer@jaguar (Marc J Balcer) Newsgroups: comp.lang.pascal Subject: Re: Converting to UPPER case Message-ID: <18594@siemens.siemens.com> Date: 17 Nov 89 22:23:59 GMT Article-I.D.: siemens.18594 References: <21481@adm.BRL.MIL> Sender: news@siemens.siemens.com Lines: 38 R1TMARG%AKRONVM.BITNET@cornellc.cit.cornell.edu (Tim Margush) writes: >... >This is something to consider for those writing programs that might be used >in both environments. After all, isn't Pascal code completely portable? Not only is portability important, but why memorize the ASCII (or EBCDIC) tables? Here's a conversion that's rather character-set independent: function uppercase (ch: char) : char; { Returns the uppercase equivalent of the given character. (If ch is already uppercase or is not a letter, it returns the value of ch unchanged. } begin if ch in ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'] then uppercase := chr (ord(ch) + ord('A') - ord('a')) else uppercase := ch end; The only assumption that this function makes is that the distance between every capital letter and its lowercase equivalent must be the same. In other words, (ord('a')-ord('A')) = (ord('b')-ord('B')) = (ord('c')-ord('C')) = ... I don't know of any character set (that has both capitals and lowercase) in which this is not true. The ugly set expression is that way because EBCDIC has "holes" in its alphabetic range: there are non-alphabetic characters in between some of the alphabetic characters. (If you knew exactly where they are you could probably shorten the expression.) --------------------------------------------------------------------------- Marc J. Balcer [balcer@cadillac.siemens.com] Siemens Research Center, 755 College Road East, Princeton, NJ 08540 (609) 734-6531