Delphi-Quellcode:
function ReverseString2(S: String): String;
var
i, i2: Integer;
begin
Result := S;
i2 := Length(S) div 2;
for i := 1 to i2 do begin
Result[i * 2 - 1] := S[(i2 - i + 1) * 2 - 1];
Result[i * 2] := S[(i2 - i + 1) * 2];
end;
end;
// oder
begin
Result := S;
i2 := Length(S) div 2;
for i := 0 to i2 - 1 do begin
Result[i * 2 + 1] := S[(i2 - i) * 2 - 1];
Result[i * 2 + 2] := S[(i2 - i) * 2];
end;
end;
Einfach ein bissl Mathematik und die passenden Zeichenoperationen.