Einzelnen Beitrag anzeigen

Overphil

Registriert seit: 19. Okt 2015
4 Beiträge
 
#6

AW: String nach bestimmten muster auflösen

  Alt 19. Okt 2015, 20:31
So, hab es mal mit der Rekursion versucht, allerdings klappt das ganze noch nicht so. Es wird jetzt nur die erste Klammerebene aufgelöst, aber sobald eine wiederholung in einer klammer ist klappt das nicht mehr.

Code:
function TForm1.getRepStr(str:string; count:integer) : string;
var repInt, bracketPlace1, bracketPlace2, i, wCount : integer;
  repStr : string;
begin

     wCount:=0;
     repInt:=getCount(str, count);
     bracketPlace1:=count+Length(IntToStr(repInt))+2;

     i:=bracketPlace1;
     while wCount<>-1 do begin
           if str[i]=')' then begin
              wCount:=wCount-1;
              if wCount=-1 then begin
                 bracketPlace2:=i+1;
                 break;
                 end;
              end
              else if str[i]='(' then begin
                   wCount:=wCount+1;
              end;
     i:=i+1;
     end;

     repStr:=Copy(str, bracketPlace1, bracketPlace2-bracketPlace1-1);

     repStr:=repeatString(repStr, repInt);
     ShowMessage('repStr: ' + repStr);
     if containsW(repStr)=true then repStr:=getRepStr(repStr, 1)
     else result:=repStr;

end;
  Mit Zitat antworten Zitat