Einzelnen Beitrag anzeigen

BlueStarHH

Registriert seit: 28. Mär 2005
Ort: Hannover-Hainholz
801 Beiträge
 
Delphi 11 Alexandria
 
#28

Re: Kann Delphi jetzt kein s[1] mehr?

  Alt 28. Mär 2005, 16:24
So wirds gemacht:

Delphi-Quellcode:
function countspacesinfront2(const s: string): Integer;
var
  i: Integer;
begin
  if Length(s) < 1 then
    Result := 0
  else
  begin
    i := 1;
    while (i <= Length(s)) and (s[i] = ' ') do
      Inc(i);
     Result := i - 1;
  end;
end;
Und die Testfälle:

Delphi-Quellcode:
  memo1.Lines.Add(IntToStr(countspacesinfront2(' Test')) + '=5');
memo1.Lines.Add(IntToStr(countspacesinfront2(' ')) + '=5');
memo1.Lines.Add(IntToStr(countspacesinfront2(' ')) + '=1');
memo1.Lines.Add(IntToStr(countspacesinfront2('')) + '=0');
memo1.Lines.Add(IntToStr(countspacesinfront2('Test')) + '=0');
  Mit Zitat antworten Zitat