Logo

Programming-Idioms

History of Idiom 41 > diff from v43 to v44

Edit summary for version 44 by holicron:
New Pascal implementation by user [holicron]

Version 43

2018-01-17, 15:42:12

Version 44

2018-01-25, 09:10:54

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration
Code
function reverse(const str: string): string;
var
  i, j: Integer;
begin
  j := length(str);
  setlength(reverse, j);
  for i := 1 to j do
    reverse[i] := str[j - i + 1];
end;