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.
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.