Delphi .NET (2) Database (72) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (243)
Exchange Links About this site Links to us
|
How to reverse a string
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Here are three examples how to reverse a string:
 | |  | |
function ReverseString( s : string ) : string;
var
i : integer;
s2 : string;
begin
s2 := '';
for i := 1 to Length( s ) do
s2 := s[ i ] + s2;
Result := s2;
end;
procedure ReverseStr(var Src : string);
var
i, j : integer;
C1 : char;
begin
j := Length(Src);
for i := 1 to (Length(Src) div 2) do
begin
C1 := Src[i];
Src[i] := Src[j];
Src[j] := C1;
Dec(j);
end;
end;
function ReverseStr(const Src : string) : string;
var
i, j : integer;
begin
j := Length(Src);
SetLength(Result, j);
for i := 1 to (Length(Src) div 2) do
begin
Result[i] := Src[j];
Result[j] := Src[i];
Dec(j);
end;
end; | |  | |  |
Comments:
|