2013-07-24

【Delphi】ReverseString - 反序顯示字串

資料來源 -- http://delphi.about.com/cs/adptips1999/a/bltip1099_3.htm


要使用 ReverseString 必須先 uses StrUtils

例如有一字串 "Chameleon"

  1. var
  2.     str: string;
  3. begin
  4.     str := 'Chameleon';
  5.     Caption := ReverseString(str);
  6. end;


執行結果顯示:"noelemahC"

但若是 Delphi 6 之前的版本,則要自己另外寫函式了 ----

  1. Function String_Reverse(S : String): String;
  2. var
  3.    i : Integer;
  4. Begin
  5.    Result := '';
  6.    For i := Length(S) DownTo 1 Do
  7.    Begin
  8.      Result := Result + Copy(S,i,1) ;
  9.    End;
  10. End;


沒有留言:

張貼留言