samedi 4 avril 2015

Trying to remove a certain character for a string unit the string only possess x amount of the character

I'm trying to remove a certain character from my string to a point where only x amount of them remain.


so what I would like to achieve is



c:\folder\new\stuff\all\more\hello\awesome\to.dll



becomes



c:\folder\new\



so far I have tired.



function RemoveLastPart(var s: string; I : integer): string;
begin
repeat
delete(s, length(s),1)
until pos ('\',s) = i;
result := s;
end;


and



function RemoveStr(var s: string; I : integer): string;
begin
while pos ('\',s) = i do
begin
delete(s, length(s),1);
result := s;
end
end;


I'm guessing I'm using pos incorrectly. I thought if a string posses '\' then do something.


since I never know how long the path will be or what folders it may or may not contain , it makes it a bit tricky.


Aucun commentaire:

Enregistrer un commentaire