Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#28

AW: führende null entfernen

  Alt 1. Aug 2018, 20:07
Delphi-Quellcode:
i:=0;
if length(mystring)>0 then begin
  repeat
    if mystring[i+1]<>'0then inc (i,1);
  until (mystring[i+1]<>'0') or (i>=length(mystring));
  if i>0 then delete(mystring,1,i);
end;
Das führt bei mir zu einer Endlos-Schleife, aber so klappts:
Delphi-Quellcode:
function DelLeadChar(const Input: string; const LeadChar: Char): string;
var
  i: Integer;
begin
  i:=0;
  Result := Input;
  if length(Input)>0 then
   begin
     repeat
       if Input[i+1]=LeadChar then inc (i,1);
// if Input[i+1]<>LeadChar then inc (i,1); // nicht gut ^_^
     until (Input[i+1]<>LeadChar) or (i>=length(Input));
     if i>0 then delete(Result,1,i);
   end;
end;
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat