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

Reverse a String

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

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

Easy ways to connect two computers for networking purposes. 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.