// 1. Groß- und Kleinschreibung tauschen
function AnsiInvertCase(s: Ansistring): Ansistring;
const
g32 = [65 .. 90, 192 .. 222];
k32 = [97 .. 122, 224 .. 254];
g16 = [138, 140, 142];
k16 = [154, 156, 158];
var
pbs, pbr: PByte;
begin
result := s;
pbs := @s[1];
pbr := @result[1];
while pbs^ > 0 do
begin
if (pbs^ in k32) then
pbr^ := pbs^ - 32
else if (pbs^ in g32) then
pbr^ := pbs^ + 32
else if (pbs^ in k16) then
pbr^ := pbs^ - 16
else if (pbs^ in g16) then
pbr^ := pbs^ + 16
else if (pbs^ = 159) then
pbr^ := 255
else if (pbs^ = 255) then
pbr^ := 159
else
pbr^ := pbs^;
inc(pbs);
inc(pbr);
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
s, v: String;
begin
s := 'ABCD abcd ÄÖÜ äöü ÁÇËÎ áçëî ŠŒŽ šœž';
v := String(AnsiInvertCase(Ansistring(s)));
showmessage(s + #13 + v);
end;
// ---------------------------------------------------------
// 2. Strings umdrehen
// Wer die Unit "StrUtils" besitzt, kann "AnsiReverseString()"
// nutzen. Ansonsten:
function FlipString(const s: string): string;
var
lg: integer;
ps, pr: PChar;
begin
lg := length(s);
setlength(result, lg);
ps := @s[1];
pr := @result[1];
inc(pr, pred(lg));
while ps^ > #0 do begin
pr^ := ps^;
inc(ps);
dec(pr);
end;
end;
// Beispielaufruf
procedure TForm1.Button3Click(Sender: TObject);
begin
Label3.caption := 'TSET NIE TSI SAD';
Label4.caption := FlipString(Label3.caption);
end;