Einzelnen Beitrag anzeigen

Elvis

Registriert seit: 25. Nov 2005
Ort: München
1.909 Beiträge
 
Delphi 2010 Professional
 
#6

Re: Buchstaben umsortieren

  Alt 17. Apr 2006, 19:25
Zitat von marabu:
Scheinbar geht es um Sortieren und Umkehren. ReverseString() ist Bestandteil der Unit StrUtils und SortedString geht zur Not so:
...
Oder so:
Delphi-Quellcode:
function ReverseString(const input : string) : string;
var
  currentChar,
  outputChar : PChar;
  beforeFirstChar : Integer;
begin
  if length(input) > 1 then
  begin
    SetLength(Result, length(input));

    beforeFirstChar := Integer(@input[1]) - SizeOf(Char);
    outputChar := @result[1];
    currentChar := @input[length(input)];

    while Integer(currentChar) > beforeFirstChar do
    begin
      outputChar^ := currentChar^;
      inc(outputChar);
      dec(currentChar);
    end;
  end
  else
   Result := input;
end;
Robert Giesecke
I’m a great believer in “Occam’s Razor,” the principle which says:
“If you say something complicated, I’ll slit your throat.”
  Mit Zitat antworten Zitat