PDA

View Full Version : toupper/tolower



Craig`
06-29-2009, 12:59 AM
The other thread got deleted as I've added toupper.
Note, this time I do not need to use one method to use another.

To compile this I used Lazarus, it will not work with SCAR as it is pure pascal at the moment.
- To get it to work, just change # := s; to result := s; and write to writeln


program blah;

function toupper(s: string): string;
var
i: integer;
begin
for i := 1 to length(s) do
begin
if s[i] in ['a'..'z'] then
begin
s[i] := chr(ord(s[i]) - 32);
end;
end;
toupper := s;
end;

function tolower(s: string): string;
var
i: integer;
begin
for i := 1 to length(s) do
begin
if s[i] in ['A'..'Z'] then
begin
s[i] := chr(ord(s[i]) + 32);
end;
end;
tolower:= s;
end;

begin
writeln(toupper('red'));
writeln(tolower('RED'));
readln;
end.

Zyt3x
06-29-2009, 04:02 AM
This is the same as LowerCase and UpperCase :)

Craig`
06-29-2009, 04:14 AM
Well yeah SCAR comes with these, but pascal doesn't originally :)

Cazax
06-29-2009, 04:23 AM
Isn't there something like this in StrUtils?

Craig`
06-29-2009, 05:43 PM
I'm not quite sure with that Cazax, anyways I found it an interesting piece of code :)