[comp.lang.pascal] TP3.01 Changing Case

garay@hyper.lap.upenn.edu (John Garay) (02/17/91)

Hi, I'm in need in some help with Turbo Pascal 3.01 and would appreciate 
assistance.

Okay, here goes:

I am trying take a string of mixed Upper and Lower Case characters and 
convert them ALL into lower case.  I would use a form such as:

	If UppercaseChar then MakeLowercase;

I just don't know how to check the chars of a string for case and even if I
did, I don't know how to convert the Upper Case chars down to Lower case.

So, you see my quandry.  The TP5.5 procedure "UpCase" is not available
w/ TP3.01...  

So, specifically, how do I check case? and How do I then convert case?
Any help would be much appreciated.    Thanks...

******************************************************************************

    John Garay            e-mail  :  garay@hyper.lap.upenn.edu
		          Office phone :  (215)  898-1954
			  Home Phone   : (215)  382-4102
			  Donations    :  4034 Walnut, Philly, PA   19104

"Change the Way People think, and things will Never be the Same."  SB

******************************************************************************

mwizard@eecs.cs.pdx.edu (Craig Nelson) (02/17/91)

garay@hyper.lap.upenn.edu (John Garay) writes:

>Hi, I'm in need in some help with Turbo Pascal 3.01 and would appreciate 
>assistance.

>Okay, here goes:

>I am trying take a string of mixed Upper and Lower Case characters and 
>convert them ALL into lower case.  I would use a form such as:

>	If UppercaseChar then MakeLowercase;

>I just don't know how to check the chars of a string for case and even if I
>did, I don't know how to convert the Upper Case chars down to Lower case.

>So, you see my quandry.  The TP5.5 procedure "UpCase" is not available
>w/ TP3.01...  

>So, specifically, how do I check case? and How do I then convert case?
>Any help would be much appreciated.    Thanks...

	
	Problem is simple in TP4.0 or later, but for you a little tricky.
Since I did not use TP3.* for the longest time I can't remember of you are
allowed to typecast characters as bytes.  I can only assume no.  What you 
need to do is take the Ord() value of the characte, and manipulate it in
such a fashion. See below:

	Procedure LowCase(Var Ch:Char);
	Var i:Integer;
	Begin
	   if (Ord(Ch)>=65 and Ord(Ch)<=90) then
		Ch:= Char(Ord(Ch)+32);
	End;

Call this on the entire array (string) whatever.  It will not touch the
non-uppercase characters, and will convert all uppercase to lower case.

	For i:= 1 to StrLen do LowCase(MyString[i]);

	Don't you love pascal ?   By the way, that function above will also
work in standard pascal, and is not limited to just the Turbo family.

	Craig (mwizard@eecs.ee.pdx.edu)

dave@tygra.UUCP (David Conrad) (02/18/91)

In article <37727@netnews.upenn.edu> garay@hyper.lap.upenn.edu (John Garay) writes:
>
>I am trying take a string of mixed Upper and Lower Case characters and 
>convert them ALL into lower case.
>
>So, you see my quandry.  The TP5.5 procedure "UpCase" is not available
>w/ TP3.01...  
>
>So, specifically, how do I check case? and How do I then convert case?

program test;

type
  strng = string[255];

function LowCase (ch : char) : char;
begin
  if (ch >= 'A') and (ch <= 'Z') then
    LowCase := chr(ord(ch) + (ord('a') - ord('A')))
  else
    LowCase := ch;
end;

function LowString (s : strng) : strng;
var
  i : integer;
begin
  for i := 1 to length(s) do
    s[i] := LowCase(s[i]);
  LowString := s;
end;

begin
  writeln (LowString('This String was in Mixed Case!'));
end.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The above program should answer your questions.  It compiled and ran in
both Turbo Pascals 3.02A and 5.5, although in 5.5 `strng' would not be
necessary as string could be used.  Also, Var-string checking should be
set to relaxed {$V-} in 5.5, I don't recall if there's an equivalent to
this in 3.x.
   Since someone is bound to comment on my use of ord('a') - ord('A')
instead of just 32, let me mention that this program could be ported to
JSPASCAL running under MTS on the system/370 mainframe down at Wayne
State U where I go to school with almost no trouble (the declaration of
strings is slightly different in JSPASCAL, strings not being supported
in standard Pascal) even though that system uses EBCDIC rather than
ASCII.  Try that with your 32 version.  If you don't know what EBCDIC
is, don't worry - be happy.  :-)
--
David R. Conrad         | "Please excuse me if I don't quite understand,
tygra!dave@uunet.uu.net | I'm just a stranger in Electric Land."
sharkey!tygra!dave      |     -- Bad Company, "Electric Land"
-- 
=  CAT-TALK Conferencing Network, Computer Conferencing and File Archive  =
-  1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.  AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET")        =
   E-MAIL Address: dave@DDMI.COM