1. Home
  2. Computing & Technology
  3. Delphi Programming

Reverse a String

By , About.com Guide

This function returns a string whose values are all reversed. The first character is last and the last is first.

Let's say you have a string 'testing string reverse' than String_reverse would result in 'esrever gnirts gnitset'.

~~~~~~~~~~~~~~~~~~~~~~~~~
Function String_Reverse(S : String): String;
Var
   i : Integer;
Begin
   Result := '';
   For i := Length(S) DownTo 1 Do
   Begin
     Result := Result + Copy(S,i,1) ;
   End;
End;
~~~~~~~~~~~~~~~~~~~~~~~~~
p.s.
Or, if you have Delphi 6+, you an use the ReverseString RTL function.

Delphi tips navigator:
» Search And Replace
« Left, Mid, Right String

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. Reverse a String

©2009 About.com, a part of The New York Times Company.

All rights reserved.