Path: utzoo!utgpu!watmath!att!rutgers!njin!princeton!udel!udccvax1!mikej From: mikej@vax1.acs.udel.EDU (Michael Jacobs) Newsgroups: comp.lang.pascal Subject: Re: uppercase and char and string[1]; Keywords: strings and chars Message-ID: <5042@udccvax1.acs.udel.EDU> Date: 17 Nov 89 03:19:22 GMT References: <5477@uhccux.uhcc.hawaii.edu> Reply-To: mikej@vax1.acs.udel.EDU (Michael Jacobs) Organization: Yoyodyne Propulsion Systems Lines: 41 >I have to declare it as type packed array [1..10] of char. My question >is, how would I change a string of that type to an all upper case string, >the way she instructed us to do it is by writing it to a file, and reading >it character by character so that you can get an upper case by the >formula chr(character+(ord('a') - ord('A')) (something like that) but >I KNOW there has to be an easier way (in standard pascal) any help would >be appreciated. > Secondly, Despite my teacher's dislike of Turbo Pascal, I broke down and >used a STRING[1] type, BUT, when I try to use ord or chr functions it >gave me a TYPE MISMATCH error, so I wanted to make it into a char character. >so I char_letter := string_letter; but the compiler would now accept it. >How do I make a single length STRING[1] type character to a CHAR character? As you may know, when you declare a variable to be, say, STRING[10], you are in reality saying ARRAY [0..10] OF CHAR, where the 0th element holds the length, and the rest the actual data. I don't know if UPCASE is a standard function; if it isn't, define it: FUNCTION UPCASE ( A : CHAR ) : CHAR; BEGIN IF A IN ['a'..'z'] THEN UPCASE = CHR ( ORD(A) - ORD('A') ) ELSE UPCASE := A END; VAR X : STRING[10]; { or ARRAY[0..10] OF CHAR } to capitalize it, IF ORD( X[0] ) > 0 THEN FOR I := 1 to ORD( X[0] ) DO X[I] := UPCASE ( X[I] ); So, when you're referring to something defined as STRING[1], it's not the same as a char, it an array of 2 chars. each element is a char. -- Mike J | The Grey Sysop... | Phone...RING!...yep yep yep yep yep! |